Click to See Complete Forum and Search --> : serial port send function problem


Scyla
February 26th, 2003, 11:04 AM
Hello, I'm writting an app for writing and reading to/from the serial port. The structure is similar to:

recognizing data function1 or function2
send command
//First time, just powered on,the device must receive that command.
//Once received that command by the device, it will answer with some data that have to be read by the
//serial port.

void function1(bufer){

switch (dataidentifier){
case A:
function
send command ---- the problem is here, this second command is never sent. The bufer value
is always the first command sent, outside the function1
case B:


case C
}
}

So the first send command works ok but not the second, and that one, if i put it outside the switch(){}, it works too but not inside it,
any idea?
Thanks in advance

Scyla
February 27th, 2003, 08:44 AM
Please, anyone understands what i m trying to ask?
thanks

Caronte
February 27th, 2003, 08:59 AM
I really donīt.

Who sends the commands?

Tell me if I have understood you...

When you start the program, you wait for commands coming from the serial port... When you receive a command, you act on it, and return a response... is it?

where is the problem? how do you implement the serial port?

KingTermite
February 27th, 2003, 09:00 AM
Was that first send command ever received on the other end?

If it works outside the switch then, my guess is that somehow you are not going into that switch statement. Can you debug/step and verify it actually goes into the statement? Then you can also go into the send() inside the switch to see what happens.

Scyla
February 27th, 2003, 09:30 AM
i actually did the debug.
1- yes , the first send is received, so the device responds with the data. That send data is outside from the XXX(char *b) function (and inside that function is where the switch statment it is). So inside the XXX(char *b) function i deal with data that is being received at the port. So,depending on what i receive i need to send a new order to the device.That new order (send function) is inside the switch loop. Debugging i could see that the serial object is empty (if i have: serial p; and i write p.send()). So debugger tells me that 'p' has no value inside the XXX() function.
And debugging the send function, when i try to go inside it, the debugger drives me to an exception handling strlen screnn. But it's strange,cause what i try to send it's the same that it's outside in the main.
thanks

KingTermite
February 27th, 2003, 09:40 AM
Sounds odd....guess we would need more code. What is a "serial" data type/class for example?

Scyla
February 27th, 2003, 09:53 AM
the serial class contains something like:
class serial{
int port;
handle file;
//functions
}

so to send a command i pit:
serial p;
p.send(data, strlen(data))

is that whta u refer to?