[Mono-list] SerialPortTest

sojan sojankallara at yahoo.com
Fri Mar 6 06:54:40 EST 2009


Thanks after adding to uucp group it works.

Orfeo wrote:
> 
> 
> sojan wrote:
>> 
>> the code is as follows please have a look
>> 
>> using System;
>> using System.IO.Ports;
>>  
>> public class SerialPortTest
>> {
>> 	public static void Main(string[] args)
>> 	{
>> 		SerialPortTest myTest = new SerialPortTest();
>> 		myTest.Test();
>> 	}
>>  
>> 	private SerialPort mySerial;
>>  
>> 	// Constructor
>> 	public SerialPortTest()
>> 	{
>> 	}
>>  
>> 	public void Test()
>> 	{
>> 		if (mySerial != null)
>> 			if (mySerial.IsOpen)
>> 				mySerial.Close();
>>  
>> 		mySerial = new
>> SerialPort("/dev/ttyS0",9600,System.IO.Ports.Parity.None,8,System.IO.Ports.StopBits.One);
>> 		mySerial.Open();
>> 		mySerial.ReadTimeout = 400;
>> 		SendData("ATI3\r");
>>  
>>                 // Should output some information about your modem
>> firmware
>> 		Console.WriteLine(ReadData());  
>> 	}
>>  
>> 	public string ReadData()
>> 	{
>> 		byte tmpByte;
>> 		string rxString = "";
>> 			
>> 		tmpByte = (byte) mySerial.ReadByte();
>>  
>> 		while (tmpByte != 255) {
>> 			rxString += ((char) tmpByte);
>> 			tmpByte = (byte) mySerial.ReadByte();			
>> 		}
>> 	
>> 		return rxString;
>> 	}
>>  
>> 	public bool SendData(string Data)
>> 	{
>> 		mySerial.Write(Data);
>> 		return true;		
>> 	}
>> }
>> 
> 
> Well, the code seems correct: are you belong to uucp group?
> 
> $>cat /etc/group| grep yourname
> $>uucp:x:14:yourname
> 

-- 
View this message in context: http://www.nabble.com/SerialPortTest-tp22324797p22369960.html
Sent from the Mono - General mailing list archive at Nabble.com.



More information about the Mono-list mailing list