10
$\begingroup$

When trying:

ser = DeviceOpen["Serial", {"COM1", "BaudRate" -> 230400}]

I get:

SerialLink`SerialPortOpen::baudrate: Value of option BaudRate -> 230400 is not
110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 56000, 57600, 
115200, 128000, 256000.

So obviously the Std BR of 230400 is not supported, although the Help for DeviceOpen in the Serial-context explicitly says:

Typical baud rate values include: 4800, 9600, 19200, 38400, 57600, 115200, 230400.

Unfortunately I need 230400 to connect to the external device. Is there any way of setting a baudrate other than through DeviceOpen?

$\endgroup$
  • 3
    $\begingroup$ 1. The Mathematica source of SerialLink is readable and found in SystemFiles/Links/SerialLink. Looking at it it is clear that the allowed baud rates are hard coded, and do not match what the documentation says (i.e. 230400 is not included). This suggests a bug. Please contact Wolfram and report it (i.e. that the docs mention 230400 but it's not supported). 2. Try modifying SerialLink`Private`$ValidBaudRates. You must run the DeviceOpen call first to trigger loading all the required bits. Once done, modify that variable, add 230400 to it, and see if it works. It might not, but try. $\endgroup$ – Szabolcs Feb 14 '16 at 12:00
  • 2
    $\begingroup$ Thank you Szabolcs. I will report it as bug. I also tried - similar to what you suggested - modifying the actual SerialLink.m File and added 230400 to the list of valid baudrates. Then DeviceOpen gave no error, but the actually transmitted bytes are garbled in this case. I guess the underlying DLL can't get close enough to this baudrate...Too bad. $\endgroup$ – swoo Feb 14 '16 at 12:45
  • $\begingroup$ What happens when you use 256000 as baud rate? $\endgroup$ – Sascha Feb 14 '16 at 16:09
  • $\begingroup$ This discussion on reddit might be relevant $\endgroup$ – Sascha Feb 15 '16 at 10:51
8
$\begingroup$

If you are under Windows, it is possible to access the RS232 port via netLink`.

<< NETLink` 
InstallNET[]

ser = NETNew["System.IO.Ports.SerialPort", "COM1"]
ser @ Open[]
ser @ BaudRate = 230400

I don't have any device at 230400 Bauds. To try the port, I have made a shortcut between pin 2 and 3 of my connector (ie Transmitter linked to Receiver) and it works :

ser @ WriteLine["Hello"]

ser @ ReadLine[]

"Hello"

To see how to use the object ser type :

NETTypeInfo[ser]

The main properties/methods are :

ser @ Open[]
ser @ Close[]
ser @ BaudRate
ser @ Parity
ser @ StopBits
ser @ ReadTimeout
ser @ DataBits
ser @ RtsEnable
ser @ CtsHolding
ser @ DsrHolding
ser @ DtrEnable
ser @ Handshake
ser @ IsOpen
ser @ PortName
| improve this answer | |
$\endgroup$
  • $\begingroup$ Sascha: The sensor I am trying to interface to is a custom thing with only "standard" Baudrate capability so the 256k aren't possible. Andre: Thank you - this is a very interesting approach. But what happens when this is supposed to work under Windows and Linux? I was hoping that using Mathematica could get me the cross-platform functionality here, but then this problem threw a wrench in it... $\endgroup$ – swoo Feb 15 '16 at 8:56
  • $\begingroup$ @swoo There is a package named SerialIO here that may be usefull (It's another solution that has nothing to do with netLink) $\endgroup$ – andre314 Feb 15 '16 at 19:56
  • $\begingroup$ Thank you for that hint. Actually that's what I tried first under Mathematica 9. That package had somehow problems with the SerialReadyQ function, so it wasn't really usable - but does allow the 230k comm! Then under 10.3 the newly integrated DeviceRead capability with a working DeviceExecute[ser, "SerialReadyQ"] function allowed robust communication but doesn't allow for the 230.4k... So I think I will have to write my own program for both Lin&Win. Anyways - thank you all! $\endgroup$ – swoo Feb 16 '16 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.