Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial port data unknown #348

Open
max-privato opened this issue Oct 20, 2021 · 2 comments
Open

Serial port data unknown #348

max-privato opened this issue Oct 20, 2021 · 2 comments

Comments

@max-privato
Copy link
Contributor

I would like to use Modelica_DeviceDrivers to send data through a serial port.
I have two PCs connected through a serial cable and can transmit and receive text through a terminal app (I use Tera Term).

When I try modelica, instead, I receive unrecognised stuff. I just I send "Hello world!" through AddString (picture below).

I think the first thing to check is the serial data:

  • data (7/8 bit)
  • parity
  • stop bits
  • flow control (Xon/Xoff, RTS/CTS, DSR/DTR, none)

While parity is under Modelica control, the other parameters are not. This is not bad per se. What is bad is that I don't know the values used by Modelica for them, and therefore cannot set the receiving PC to the right setting.

Can someone tell to me what values for the above communication parameters are used by SerialPortSend?

@bernhard-thiele
Copy link
Collaborator

As mentioned in #350 (comment) I'm not very knowledgeable in the serial port intricacies. I agree that the settings belong into the documentation and ideally should be the same on Windows and Linux :-). For the time being one needs to look into the C code external object constructors to figure out the configuration details (and I don't claim understanding everything in detail). In the external object constructor for Windows one finds

dcb.fBinary = 1;
dcb.ByteSize = 8;
dcb.StopBits = ONESTOPBIT;
dcb.fDsrSensitivity = FALSE;
dcb.fOutX = FALSE;
dcb.fInX = FALSE;
dcb.fErrorChar = FALSE;
dcb.fRtsControl = RTS_CONTROL_ENABLE;
dcb.fAbortOnError = TRUE;
dcb.fOutxCtsFlow = FALSE;
dcb.fOutxDsrFlow = FALSE;

and

if (!GetCommMask(serial->hComm, &fdwEventMask)) {
fdwEventMask = 0;
}
fdwEventMask |= EV_RXCHAR | EV_TXEMPTY | EV_BREAK | EV_ERR | EV_RING | EV_RLSD | EV_CTS | EV_DSR;
SetCommMask(serial->hComm, fdwEventMask);
EscapeCommFunction(serial->hComm, SETDTR);
PurgeComm(serial->hComm, PURGE_TXABORT | PURGE_TXCLEAR);
PurgeComm(serial->hComm, PURGE_RXABORT | PURGE_RXCLEAR);

@max-privato
Copy link
Contributor Author

After I opened this ticket I successfully exchanged info between teraterm and OM via Modelica-DeviceDrivers+serial port successfully. To do this, I left Teraterm with the default setting, i.e. 8N1 (Parity none, o data bits, 1 stop bit)

So, this strongly suggests that this, 8N1, is the setup of serial port of Modelica_DeviceDrivers.

Now I read on your message

dcb.ByteSize = 8; 
dcb.StopBits = ONESTOPBIT; 

which confirms the assumption (moreover, I don't believe that the two ports can dialogue with unmatched settings)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants