Forums

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

Hello,
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.
Thanks
heartm8
 
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:

https://www.google.com/search?q=.net+rs-232

https://www.google.com/search?q=mono+rs-232
Charles
 
Posts: 2515
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 'http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx'
= 2nd hit in .Net search above - quick converted to a Cobra program.

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

class SerPort
shared
# 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

.sendSampleData
#.rcvSampleData

def sendSampleData is shared
#Open the port for communications
try
.port.open
catch ioe as System.IO.IOException
print ioe.message
CobraCore.exit(1)

# 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
.port.close


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
.port.open
# Enter an application loop to keep this thread alive - GUI program - otherwise use a reader Thread
Application.run

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)
hopscc
 
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.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 22 guests

cron