RS-232 class libraries/support?

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

RS-232 class libraries/support?

Postby heartm8 » Sun Jun 02, 2013 6:10 pm

Most of my hobbyist programs involve parsing data streams from equipment. Is this supported in Cobra. I did do a search for RS-232 and found nothing on the forum.
Posts: 1

Re: RS-232 class libraries/support?

Postby Charles » Sun Jun 02, 2013 9:29 pm

Cobra can leverage libraries from the .NET/Mono community. You'll get useful hits with these searches:
Posts: 2512
Location: Los Angeles, CA

Re: RS-232 class libraries/support?

Postby hopscc » Mon Jun 03, 2013 2:13 am

Heres some of the example code at ''
= 2nd hit in .Net search above - quick converted to a Cobra program.

use System.IO.Ports
use System.Windows.Forms

class SerPort
# Instantiate the communications port with some basic settings
var port = SerialPort("COM1", 9600, Parity.None, 8, StopBits.One)

def main is shared
print 'serialPorts:'
for s in SerialPort.getPortNames
print s


def sendSampleData is shared
#Open the port for communications
catch ioe as System.IO.IOException
print ioe.message

# Write a string
.port.write("Hello World")
# Write a set of bytes
.port.write(@[0x0A_u8, 0xE2_u8, 0xFF_u8], 0, 3)

# Close the port

def rcvSampleData is shared

print "Incoming Data:"

# Attach a method to be called when there is data waiting in the port's buffer
# C#: port.DataReceived += newSerialDataReceivedEventHandler( port_DataReceived )
listen .port.dataReceived, SerialDataReceivedEventHandler(ref .port_DataReceived )
# Begin communications
# Enter an application loop to keep this thread alive - GUI program - otherwise use a reader Thread

def port_DataReceived(sender as Object, e as SerialDataReceivedEventArgs) is shared
# Show all the incoming data in the port's buffer
Console.writeLine( .port.readExisting)
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: RS-232 class libraries/support?

Postby Charles » Mon Jun 03, 2013 12:26 pm

Thanks hopscc. I added this to the wiki at SerialPort.
Posts: 2512
Location: Los Angeles, CA

Return to Discussion

Who is online

Users browsing this forum: No registered users and 6 guests