Fazecast / jSerialComm

Platform-independent serial port access for Java
GNU Lesser General Public License v3.0
1.35k stars 287 forks source link

Initializing DTR and RTS before opening port. #248

Closed HannesBulk closed 5 years ago

HannesBulk commented 5 years ago

I want to use the serialport without setting DTR or RTS lines. By default the settings are to set both ON. You can do this by calling clerrRTS() of ClearDTR(), this works both before and after opening the serial port. However, when calling this function before opening a status report is send to the output screen (in NetBeans 8.2). When applying these command after opening, no report is send.

I can only use the option to open the port with the first method, applying before opening, because when I do thes after opening the Arduino connected will reset, due to e short puls on the RTS line. How can I suppress the status rapport in the output screen ????

This also happens when setting the baudrate, parity or nr of stopbits, but this can be suppressed by using the setCommPortParameters command.

Perheaps this can also be accomplished by adding extra options in the FLOW_CONTROL options. Usefull extra options are DTR_HIGH, DTR_LOW, RTS_HIGH and RTS_LOW to force these settings. I think this is the best place to do so, because this is where you define the usage of DTR and RTS lines.

Also usefull can be to have better control of the RS485 mode. Now is is only possible to use the DTR line, while some chips only have RTS. So a nice addition would be to have extra options in the RS485 support, to use the RTS line and to control the levels: Output now is DTR_HIGH is transmitting, extra options can be DTR_LOW = Transmitting, RTS_HIGH = transmitting, RTS_LOW = transmitting. Also be carefull what to du during a BREAK state. On the FTDI chips the TXEN is set during both a transmission and a Break, on the chinese CH330/340 chips with a TNOW output this output is only set during a normal transmission, not during a break. Both can be usefull, so in a perfect solution this should be covered with the same set of parameters what to do during a Break. If this is to complex I suggest to not set this output during a break, giving the user the option to set this lines under program control with set/Clear DTR/RTS commands.

hedgecrw commented 5 years ago

As to the first issue about jSerialComm outputting informational messages to the console, I just implemented a fix that should suppress all of this. Please test the following and verify that this works for you:

https://www.dropbox.com/s/kjlc2i2eh836p1h/jSerialComm-2.5.3.jar?dl=0

As to increasing control over the RS485 mode, is this something you are needing for your own projects, or just something that you think would be beneficial? If it's the latter, I would like to defer doing anything until someone has an actual need for this since 1) it seems like this will add quite a bit of complexity to the code which I'm trying to keep as simple as possible, 2) it sounds like it will be difficult to implement in a truly "generic" fashion between different chip manufacturers and types, and 3) I have no way of testing any of the RS485 functionality, so this will be quite painful to blindly implement without the ability to debug on my end. If you do have an actual need for this, let me know, and we can figure out the best way to proceed. Thanks!

HannesBulk commented 5 years ago

Sorry, but the when trying the program with this new try version the program crashes when calling setRTS before opening the port. (no crashes when calling after opening). I included a copy of the documented source file, and an output screendump with the old version 2.5.2 and the new version 2.5.3.

The extra handshake options with DRT and /or RTS low/High are not needed when the issue with the text generated is solved.

The RS485 software handshake is now using the RTS pin. New cheap low-pincount chips (CH330) don't han an RTS line, only a RTS line. So is is usefull when using these chips. Using the hardware implementations is also an option, but the problem is that the TXEN pin (on FTDI chips) and the TNOW pin on CH340 chips are not identical during a BREAK command. So if you wont to write an application working with both chips, this hardware solution is good as long as you are not using a BREAK.

Attachment: Test new version.zip

HannesBulk commented 5 years ago

I hope you can correct the proposed version 2.5.3, it didn't work, see attachment above

HannesBulk commented 5 years ago

Forget about the RS485 problems, this can also be done in software by toggeling the RTS line before and after sending the data. the problem to solve now is the suppression of (wrong) status rapports when changing RTS or DTR before opening the serial port. (in my example i did set the mode to 8 databits before changing the RTS line, and the (unwanted) rapport tells me something different !!! So the report isn't only not wanted, is is also wrong.

hedgecrw commented 5 years ago

Please try the following version: https://www.dropbox.com/s/tipdttj7ww6gvqi/jSerialComm-2.5.3a.jar?dl=0

The code changes were resulting in a string buffer overflow in the last version I sent you. This one appears to be working on my machine. Thanks.

HannesBulk commented 5 years ago

This version seems OK, works under windows 10 without problems. Thx.

Op di 29 okt. 2019 om 17:40 schreef Will Hedgecock <notifications@github.com

:

Please try the following version: https://www.dropbox.com/s/tipdttj7ww6gvqi/jSerialComm-2.5.3a.jar?dl=0

The code changes were resulting in a string buffer overflow in the last version I sent you. This one appears to be working on my machine. Thanks.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Fazecast/jSerialComm/issues/248?email_source=notifications&email_token=AHUL57NFNKQECVCKGNW4JG3QRBRQZA5CNFSM4JAHGDX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECRHDFA#issuecomment-547516820, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHUL57PLN6QCSMNSRYCPYOLQRBRQZANCNFSM4JAHGDXQ .

HannesBulk commented 5 years ago

Problem is now solved, world good under Windiws 10. Thx

Op di 29 okt. 2019 om 17:40 schreef Will Hedgecock <notifications@github.com

:

Please try the following version: https://www.dropbox.com/s/tipdttj7ww6gvqi/jSerialComm-2.5.3a.jar?dl=0

The code changes were resulting in a string buffer overflow in the last version I sent you. This one appears to be working on my machine. Thanks.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Fazecast/jSerialComm/issues/248?email_source=notifications&email_token=AHUL57NFNKQECVCKGNW4JG3QRBRQZA5CNFSM4JAHGDX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECRHDFA#issuecomment-547516820, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHUL57PLN6QCSMNSRYCPYOLQRBRQZANCNFSM4JAHGDXQ .

HannesBulk commented 5 years ago

Will this improvement be included in a new version ? Please inform me about the planning for a new release, would be nice if this will be available for general download bij Xmas 2019.

hedgecrw commented 5 years ago

Fixed - this is present in current jSerialComm release v2.5.3.