Discussion:
Serial Port Debugging?
Jim Wagner
2017-04-07 22:07:21 UTC
Permalink
Greetings -

I seem to have a tough problem here. There are quite a few details so please bear with me.

1. I am trying to set up several virtual (USB) serial ports to talk to multiple microcontroller devices of my design. The devices work through the USB/Serial port as I can access each one, individually, using a standard terminal program. The program is a several year old XOJO app that I wrote so I have at least a little experience with this stuff.

2. Architecturally, I have a class Channel that has a property (class) TheSerial of type Serial. Then I have a module containing a property TheChannels, which is an “array" property of type Channel. There are 8 members of this array.

3. Each class Channel also has a method MySerialDataAvailable that has a parameter TheSerial as Serial. As each new instance of TheChannels is created (using New) and various properties are assigned values and each corresponding instance of TheSerial is Newed, the statement

AddHandler TheChannels(Idx).TheSerial.DataAvailable, AddressOf TheChannels(Idx).MySerialDataAvailable

is executed. The purpose is to give TheChannels(Idx).TheSerial a DataAvailable event handler. Yes, TheSerial is Newed before this statement is executed!

4. When I write a predetermined command to the virtual serial port using TheChannels(Idx).TheSerial.Write(CommandString), I can see the Rx LED flash on the remote device, indicating that the command was received and the Tx LED on the remote device flash, indicating that a response was transmitted (exactly the same as when the ordinary terminal program was used).

5. HOWEVER, the DataAvailable event never fires. I suspect that there is something wrong with the AddHandler statement but I am at a loss to see what it is or how to diagnose what it might be or even to determine whether or not that is, in fact, the problem. In particular, do I have the AddressOf specification correct?

Hope someone with a bit of experience can help point me in a useful direction.

Many thanks
Jim

James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>




_____________________________________________
Jim PITCHFORD
2017-04-07 22:37:29 UTC
Permalink
Jim

Not an expert but when I've used add handler it has always pointed to a single method, i.e. Not chosen when the event is fired but when the addhandler is created.

Jim

Sent from my iPhone
Post by Jim Wagner
Greetings -
I seem to have a tough problem here. There are quite a few details so please bear with me.
1. I am trying to set up several virtual (USB) serial ports to talk to multiple microcontroller devices of my design. The devices work through the USB/Serial port as I can access each one, individually, using a standard terminal program. The program is a several year old XOJO app that I wrote so I have at least a little experience with this stuff.
2. Architecturally, I have a class Channel that has a property (class) TheSerial of type Serial. Then I have a module containing a property TheChannels, which is an “array" property of type Channel. There are 8 members of this array.
3. Each class Channel also has a method MySerialDataAvailable that has a parameter TheSerial as Serial. As each new instance of TheChannels is created (using New) and various properties are assigned values and each corresponding instance of TheSerial is Newed, the statement
AddHandler TheChannels(Idx).TheSerial.DataAvailable, AddressOf TheChannels(Idx).MySerialDataAvailable
is executed. The purpose is to give TheChannels(Idx).TheSerial a DataAvailable event handler. Yes, TheSerial is Newed before this statement is executed!
4. When I write a predetermined command to the virtual serial port using TheChannels(Idx).TheSerial.Write(CommandString), I can see the Rx LED flash on the remote device, indicating that the command was received and the Tx LED on the remote device flash, indicating that a response was transmitted (exactly the same as when the ordinary terminal program was used).
5. HOWEVER, the DataAvailable event never fires. I suspect that there is something wrong with the AddHandler statement but I am at a loss to see what it is or how to diagnose what it might be or even to determine whether or not that is, in fact, the problem. In particular, do I have the AddressOf specification correct?
Hope someone with a bit of experience can help point me in a useful direction.
Many thanks
Jim
James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

https:/
Jim Wagner
2017-04-07 22:46:20 UTC
Permalink
Thanks,

Thats what I tried to do here. The AddHandler runs during the creation of the “array” element that contains a Newed Serial object. If you think my explanation suggests otherwise, please point to where you see that, because I don’t.

Appreciate your suggestion.

Jim

James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by Jim PITCHFORD
Jim
Not an expert but when I've used add handler it has always pointed to a single method, i.e. Not chosen when the event is fired but when the addhandler is created.
Jim
Sent from my iPhone
Post by Jim Wagner
Greetings -
I seem to have a tough problem here. There are quite a few details so please bear with me.
1. I am trying to set up several virtual (USB) serial ports to talk to multiple microcontroller devices of my design. The devices work through the USB/Serial port as I can access each one, individually, using a standard terminal program. The program is a several year old XOJO app that I wrote so I have at least a little experience with this stuff.
2. Architecturally, I have a class Channel that has a property (class) TheSerial of type Serial. Then I have a module containing a property TheChannels, which is an “array" property of type Channel. There are 8 members of this array.
3. Each class Channel also has a method MySerialDataAvailable that has a parameter TheSerial as Serial. As each new instance of TheChannels is created (using New) and various properties are assigned values and each corresponding instance of TheSerial is Newed, the statement
AddHandler TheChannels(Idx).TheSerial.DataAvailable, AddressOf TheChannels(Idx).MySerialDataAvailable
is executed. The purpose is to give TheChannels(Idx).TheSerial a DataAvailable event handler. Yes, TheSerial is Newed before this statement is executed!
4. When I write a predetermined command to the virtual serial port using TheChannels(Idx).TheSerial.Write(CommandString), I can see the Rx LED flash on the remote device, indicating that the command was received and the Tx LED on the remote device flash, indicating that a response was transmitted (exactly the same as when the ordinary terminal program was used).
5. HOWEVER, the DataAvailable event never fires. I suspect that there is something wrong with the AddHandler statement but I am at a loss to see what it is or how to diagnose what it might be or even to determine whether or not that is, in fact, the problem. In particular, do I have the AddressOf specification correct?
Hope someone with a bit of experience can help point me in a useful direction.
Many thanks
Jim
James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

https://forum.x
V S Cordero
2017-04-07 22:46:37 UTC
Permalink
Hi Jim,

My first question is why Channel isn’t a subclass of Serial, so you can implement DataAvailable directly.

Also, another Jim mentioned AddHandler being assigned once. This is true, although I understand you can reassign after a RemoveHandler, though I never use it.

If subclassing isn’t the solution, and you do need to swap handlers (I didn’t get that in my fast read-through) then thats normally what ‘Delegates' are for IIRC, to treat methods like variables that you can set conditionally.

Cheers

Vaughn
Post by Jim Wagner
Greetings -
I seem to have a tough problem here. There are quite a few details so please bear with me.
1. I am trying to set up several virtual (USB) serial ports to talk to multiple microcontroller devices of my design. The devices work through the USB/Serial port as I can access each one, individually, using a standard terminal program. The program is a several year old XOJO app that I wrote so I have at least a little experience with this stuff.
2. Architecturally, I have a class Channel that has a property (class) TheSerial of type Serial. Then I have a module containing a property TheChannels, which is an “array" property of type Channel. There are 8 members of this array.
3. Each class Channel also has a method MySerialDataAvailable that has a parameter TheSerial as Serial. As each new instance of TheChannels is created (using New) and various properties are assigned values and each corresponding instance of TheSerial is Newed, the statement
AddHandler TheChannels(Idx).TheSerial.DataAvailable, AddressOf TheChannels(Idx).MySerialDataAvailable
is executed. The purpose is to give TheChannels(Idx).TheSerial a DataAvailable event handler. Yes, TheSerial is Newed before this statement is executed!
4. When I write a predetermined command to the virtual serial port using TheChannels(Idx).TheSerial.Write(CommandString), I can see the Rx LED flash on the remote device, indicating that the command was received and the Tx LED on the remote device flash, indicating that a response was transmitted (exactly the same as when the ordinary terminal program was used).
5. HOWEVER, the DataAvailable event never fires. I suspect that there is something wrong with the AddHandler statement but I am at a loss to see what it is or how to diagnose what it might be or even to determine whether or not that is, in fact, the problem. In particular, do I have the AddressOf specification correct?
Hope someone with a bit of experience can help point me in a useful direction.
Many thanks
Jim
James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

https://forum.xojo.c
Jim Wagner
2017-04-07 22:52:45 UTC
Permalink
Hello, Vaughn -

Can I only AddHandler to one of the Serial classes? I would have thought that each Serial would get its own handler.

At least, that is what I try to do. The Handler is a method of the original Channel class.

I did not think of making Channel a subclass of Serial. That might simplify things a lot. I will try that.

Jim

James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by V S Cordero
Hi Jim,
My first question is why Channel isn’t a subclass of Serial, so you can implement DataAvailable directly.
Also, another Jim mentioned AddHandler being assigned once. This is true, although I understand you can reassign after a RemoveHandler, though I never use it.
If subclassing isn’t the solution, and you do need to swap handlers (I didn’t get that in my fast read-through) then thats normally what ‘Delegates' are for IIRC, to treat methods like variables that you can set conditionally.
Cheers
Vaughn
Post by Jim Wagner
Greetings -
I seem to have a tough problem here. There are quite a few details so please bear with me.
1. I am trying to set up several virtual (USB) serial ports to talk to multiple microcontroller devices of my design. The devices work through the USB/Serial port as I can access each one, individually, using a standard terminal program. The program is a several year old XOJO app that I wrote so I have at least a little experience with this stuff.
2. Architecturally, I have a class Channel that has a property (class) TheSerial of type Serial. Then I have a module containing a property TheChannels, which is an “array" property of type Channel. There are 8 members of this array.
3. Each class Channel also has a method MySerialDataAvailable that has a parameter TheSerial as Serial. As each new instance of TheChannels is created (using New) and various properties are assigned values and each corresponding instance of TheSerial is Newed, the statement
AddHandler TheChannels(Idx).TheSerial.DataAvailable, AddressOf TheChannels(Idx).MySerialDataAvailable
is executed. The purpose is to give TheChannels(Idx).TheSerial a DataAvailable event handler. Yes, TheSerial is Newed before this statement is executed!
4. When I write a predetermined command to the virtual serial port using TheChannels(Idx).TheSerial.Write(CommandString), I can see the Rx LED flash on the remote device, indicating that the command was received and the Tx LED on the remote device flash, indicating that a response was transmitted (exactly the same as when the ordinary terminal program was used).
5. HOWEVER, the DataAvailable event never fires. I suspect that there is something wrong with the AddHandler statement but I am at a loss to see what it is or how to diagnose what it might be or even to determine whether or not that is, in fact, the problem. In particular, do I have the AddressOf specification correct?
Hope someone with a bit of experience can help point me in a useful direction.
Many thanks
Jim
James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
______________________________________________
Jim Wagner
2017-04-08 07:38:10 UTC
Permalink
Vaughn - Thanks for those hints!

It took me several tries and swimming 20 laps to realize the import of your suggestion. Making that top-level class inherit from Serial so that it could have a “native” DataAvailable handler did the trick., Works like a champ!

Best wishes,
Jim

James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by Jim Wagner
Hello, Vaughn -
Can I only AddHandler to one of the Serial classes? I would have thought that each Serial would get its own handler.
At least, that is what I try to do. The Handler is a method of the original Channel class.
I did not think of making Channel a subclass of Serial. That might simplify things a lot. I will try that.
Jim
James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
Post by V S Cordero
Hi Jim,
My first question is why Channel isn’t a subclass of Serial, so you can implement DataAvailable directly.
Also, another Jim mentioned AddHandler being assigned once. This is true, although I understand you can reassign after a RemoveHandler, though I never use it.
If subclassing isn’t the solution, and you do need to swap handlers (I didn’t get that in my fast read-through) then thats normally what ‘Delegates' are for IIRC, to treat methods like variables that you can set conditionally.
Cheers
Vaughn
Post by Jim Wagner
Greetings -
I seem to have a tough problem here. There are quite a few details so please bear with me.
1. I am trying to set up several virtual (USB) serial ports to talk to multiple microcontroller devices of my design. The devices work through the USB/Serial port as I can access each one, individually, using a standard terminal program. The program is a several year old XOJO app that I wrote so I have at least a little experience with this stuff.
2. Architecturally, I have a class Channel that has a property (class) TheSerial of type Serial. Then I have a module containing a property TheChannels, which is an “array" property of type Channel. There are 8 members of this array.
3. Each class Channel also has a method MySerialDataAvailable that has a parameter TheSerial as Serial. As each new instance of TheChannels is created (using New) and various properties are assigned values and each corresponding instance of TheSerial is Newed, the statement
AddHandler TheChannels(Idx).TheSerial.DataAvailable, AddressOf TheChannels(Idx).MySerialDataAvailable
is executed. The purpose is to give TheChannels(Idx).TheSerial a DataAvailable event handler. Yes, TheSerial is Newed before this statement is executed!
4. When I write a predetermined command to the virtual serial port using TheChannels(Idx).TheSerial.Write(CommandString), I can see the Rx LED flash on the remote device, indicating that the command was received and the Tx LED on the remote device flash, indicating that a response was transmitted (exactly the same as when the ordinary terminal program was used).
5. HOWEVER, the DataAvailable event never fires. I suspect that there is something wrong with the AddHandler statement but I am at a loss to see what it is or how to diagnose what it might be or even to determine whether or not that is, in fact, the problem. In particular, do I have the AddressOf specification correct?
Hope someone with a bit of experience can help point me in a useful direction.
Many thanks
Jim
James Wagner
Oregon Research Electronics
http://www.orelectronics.net <http://www.orelectronics.net/>
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________
https://forum.xojo.com/
_______________________________________________

Xojo forum:

https://for

Continue reading on narkive:
Loading...