To use Serial Manager to send and receive data over the serial
Like in any form of communication, you need senders and receivers.
Here, we'll deal with one client that
sends requests to a server,
which in turn sends a reply to the
client. Each of those two guys will have to send and receive something.
Here's the small collection of APIs we'll use. It's only a subset
of Serial Manager's APIs, but it's
actually the functions that you will most likely use for serial
- SrmOpen(logical_port, baud_rate, &port)
- SrmSend(port, buffer, number_of_bytes,
- SrmReceive(port, buffer, number_of_bytes,
- SrmReceiveFlush(port, timeout)
Download the ZIP file.
This apps runs on POSE as a client. The server is written in Java
and is included in the tutorial. On client UI, you'll be able to
request current date, current time, or simulate a communication
error with the server. The server replies accordingly by sending
date, time or an error message. Server UI just displays incoming
requests and outgoing replies.
- add following IDs for our buttons: MainDownloadDate, MainDownloadTime,
- add that one for our reply field: MainReply
- add "Date" button with ID MainDownloadDate
(refer to how UI looks on top of this page)
- add "Time" button with ID MainDownloadTime
- add "Crap" button with ID MainDownloadCrap
- add "Reply" field with ID
MainReply (it's LEFTALIGN NONEDITABLE UNDERLINED
and MAXCHARS 100)
- add VERSION 1 "1.0.0"
- add LAUNCHERCATEGORY ID 1000 "Tutorial"
- declare variable port as a UInt16
and set it to zero
- in MainFormHandleEvent()/case MainDownloadDate, flush receive
port: SrmReceiveFlush(port, 0);
- and send "DATE" request: SrmSend(port,
"DATE\n", 5, &err);
- a bit further, flush send port: SrmSendFlush(port);
- and receive data: SrmReceive(port, ptr,
1, 10, &err)
- in MainFormHandleEvent()/case MainDownloadTime, flush receive
port as above
- and send "TIME" command
- in AppStart(), add this blocklet of code to open port and launch
if ((retcode = SrmOpen(serPortCradlePort,
115200, &port)) == 0)
- in AppStop(), close all open forms and close comm port:
retcode = SrmClose(port);
- you don't need to do anything, it's ready to use :)
Make the app. On your desktop double-click on Serial.bat (or run
'java Serial <port>' from a command prompt) to execute the
server Java class, THEN run this client app on POSE. Argument <port>
must match POSE setting (usually 6416).
Here's the ZIP file.
And here's how the app should like: