The windows computer can send information to the linux computer over the serial port no problem. However whenever I call Write() on the linux computer nothing seems to happen.
Here is the linux code:
//This code opens the serial port. Sorry for some of the run around with variables. I planned on fixing it later on
int fd;
string serialName = settings->GetSettingStr("arduino.SerialPortName");
struct termios options;
int port;
memset(&options,0,sizeof(options));
this->worldState = worldState;
this->settings = settings;
worldState->LastArduinoPacketTime = Time::Now(); //This gives the arduino some time to respond
if ((port = open(serialName.c_str(), O_RDWR | O_NOCTTY | O_NDELAY)) < 0) {
throw -1;
}
serialPortHandle = fd = port; //Uhm I think this is how this works?
dataBuffer = new Ring<byte>(1024); //Up to a kilobyte of data in the ring buffer!
//Allow read operation to be non-blocking. (Hurray!)
fcntl(fd, F_SETFL, FNDELAY);
if (tcgetattr(fd,&options) != 0) {
throw -99; //TODO: Make this error message valid
}
cfsetispeed(&options, settings->GetSettingInt("arduino.Baud"));
cfsetospeed(&options, settings->GetSettingInt("arduino.Baud"));
options.c_cflag = (options.c_cflag & ~CSIZE) | CS8;
options.c_iflag &= IGNBRK;
options.c_lflag = 0;
options.c_oflag = 0;
options.c_iflag &= ~(IXON | IXOFF | IXANY);
options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag &= ~(PARENB | PARODD);
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CRTSCTS;
if (tcsetattr(fd, TCSANOW, &options) != 0) {
throw -99; //TODO: Make this error message valid
}
serialPortHandle = fd;
serialPortRunning=true;
//This code is in a different method and is what is doing the writing. Setting a breakpoint here verifies it is being called correctly
if (write(serialPortHandle,packet,length) < 0) {
Console::Log << "\nALR 005 Serial port connection write failed.\n";
serialPortRunning=false;
}
And Here's the C# code:
//This opens the port on the windows side
openedPort = new SerialPort(whichSerial, baud, Parity.None, 8, StopBits.One);
openedPort.ReceivedBytesThreshold = 1;
openedPort.Open(); //Exceptions handled by next layer up.
if (!openedPort.IsOpen)
throw new Exception("Unable to open serial port.");
openedPort.DataReceived += DataReceivedHandler;
this.callingForm = callingForm;
this.sim = sim;
//This never gets called
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
}
I've identified 5 different properties which need to be the same for serial ports to work:
Handshake type,
Baud,
Parity,
Data bits,
Stop bit(s).
The serial port can receive information sent from the windows computer no problem, so as far as I know most of these must be correct. However, something is preventing the linux computer from sending any data, or the windows computer from receiving any data.
This post has been edited by wd40bomber7: 24 July 2012 - 11:54 AM

New Topic/Question
Reply




MultiQuote






|