Reading SeaTalk data using Microsoft Communications Control in VisualBasic
On the website of Thomas Knauf (http://www.thomasknauf.de/seatalk.htm), the details of the SeaTalk protocol are discussed, and also the interface with a PC. Based on this information it is possible to read and process Seatalk input data in VisualBasic, using the Microsoft Communications Control. The advantage is obvious: we can directly interpret the SeaTalk input, and display the data on our Computer Navigation Centre. Below, we discuss how this is accomplished.
The practice of SeaTalk to set the parity bit, in order to signal a new datagram, is not the same as creating a parity condition in regular data transmission. Normally, the number of bits set in a byte is counted, and the parity bit is set to make the total bits even or odd (depending on the parity setting, see http://support.microsoft.com/default.aspx?scid=kb;en-us;52196 for an explanation). A further complication may be, that the after the parity event is raised by the Communications Control, when characters continue to be received, the parity event may be raised again. But if there is more than one character in the input buffer, it is not clear which character raised the parity condition.
As a workaround we will process the parity event as soon as it is raised, and then quickly process all remaining characters in the buffer, assuming these caused no parity. In my experience, this works quite well, creating less than a few percent wrong incorrect receptions.
The code example (SeaTalkTest.vbp) provided in attached zip file demonstrates this approach. It employs three key functions:
Public Function SetSeaTalkCom(myPort As Integer, myCom As MSComm) As Boolean
Opens the input port (myPort) using the Communications Control (myCom), with the
|.Settings = "4800,S,8,1"||4800 baud, Space, 8 data, and 1 stop bit.|
|.ParityReplace = ""||Parity will be detected by OnComm event, character will still be used|
|.InputMode = comInputModeBinary||Expect also Hex 00 characters, and process data as a binary array, not as a text string|
|.Handshaking = comNone||SeaTalk has no handshaking|
|.InputLen = 1||We will process 0ne character at a time|
|.RThreshold = 1||We will react when we get the character|
Public Sub MSCommSeaTalkChar(myComm As MSComm, SeaTalkMode As Integer, mymsg As String, myMsgNum As Integer, Optional myInp As String)
Called by myComm_OnComm whenever a Communication event is raised on MsComm. It processes and stores the
parity event, if received, and if called in a receive condition processes any characters available in the input buffer.
|MyComm||the Communications Control we are using|
|SeaTalkMode|| Public Const SeaTalkModeBoat = 1 (look at parity bit and parity algorithm)
Public Const SeaTalkModeSim = 2 (only look at parity bit)
|myMsg||will contain the message received, if a complete message was received|
|myMsgNum||will contain the SeaTalk message number of above|
|myInp||hex representation of any input bytes received will be appended to this string, if provided|
Function DoSeaTalkMessage(b() As Byte) As String
When we have a full SeaTalk Message in our input buffer array (b()), we call this function to process the message. It returns a legible string.
Although this code has demonstrated to work in my case (Pentium processor, Windows XP, three instruments on SeaTalk bus), no guarantees can be given. Also from time to time we detect improvements, which are implemented without notice. Any suggestions are welcome at : 'zee "@" pbeekman.com' (replace ' " ' by '@' for spam protection)
- seatalktestp.zip this documentation + vb project
- seatalktestc.zip complete setup package for executable
- seatalktestx.zip executable only
This page is available from: http://pbeekman.com/seatalk
Also take a look at look at http://pbeekman.com/seatrack.htm, which can be used to process seatalk input directly as well.
Thomas Knauf website on Seatalk: http://www.thomasknauf.de/seatalk.htm
Microsoft knowledgebase on parity:http://support.microsoft.com/default.aspx?scid=kb;en-us;52196