MessagePort USB problem

Working on a instrument project or just finished a project? Show it to others!

Moderators: Ralph, russ

Message
Author
Detlef
Posts: 122
Joined: Mon Nov 16, 2020 9:43 am
Location: Bavaria

MessagePort USB problem

#1 Post by Detlef » Fri Apr 02, 2021 9:55 am

Hello,

I am using the MessagePort interface for my hardware. Most of the time that works fine but sometimes when I start the AM instrument, the instrument cannot connect to my Arduino Mega based hardware. I use in Lua
gFlexpanelMessagePortID = hw_message_port_add("ARDUINO_MEGA2560_A", cbMessageFromFlexpanel).

I wonder if my USB cable extension is unreliable or too long or if my USB port on the PC causes problems. For that I sometimes have to reboot and/or pull and replug the USB connector. Sometimes it helps to just try several times to start the instrument. Then, once it is running it is running fine. And if it worked once after power on, then it works also after stopping the instrument and starting it again, regardless how often.

Any help/ideas are appreciated.

Thank you
Detlef

User avatar
Ralph
Posts: 5164
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: MessagePort USB problem

#2 Post by Ralph » Fri Apr 02, 2021 10:42 am

Did you check if the Arduino shows that it is connected in Air Manager?

User avatar
jph
Posts: 763
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: MessagePort USB problem

#3 Post by jph » Fri Apr 02, 2021 10:49 am

Just as a thought - have you checked you have 'connect to arduino devices automatically' ticked in settings ?
I was playing around with a diy knobster a few weeks back and couldn't understand why it seemed to connect sometimes and not others. The box was unchecked for some reason. I was totally confused, but that is nothing unusual for me.. :lol:
“Everything in moderation, including moderation.”
“Experience is merely the name men gave to their mistakes.”
Joe (CISSP) -IT security consultant

Detlef
Posts: 122
Joined: Mon Nov 16, 2020 9:43 am
Location: Bavaria

Re: MessagePort USB problem

#4 Post by Detlef » Sat Apr 03, 2021 8:59 am

Ralph wrote:
Fri Apr 02, 2021 10:42 am
Did you check if the Arduino shows that it is connected in Air Manager?
Ralph,

thank you, yes that box is checked.

Detlef

Detlef
Posts: 122
Joined: Mon Nov 16, 2020 9:43 am
Location: Bavaria

Re: MessagePort USB problem

#5 Post by Detlef » Sat Apr 03, 2021 9:21 am

jph wrote:
Fri Apr 02, 2021 10:49 am
The box was unchecked for some reason. I was totally confused, but that is nothing unusual for me.. :lol:
jph
:) I know what you mean. Sometimes I keep trying and don't realize that Airmanager is running twice. But yes here, the automatic connection to Arduino is checked. And today it works.

If I remember right I have tried to run hw_message_port_id = hw_message_port_add(name, message_callback)
in a loop inside a function and got the error message that function must be outside any function. So I just call it once at instrument start. Then I start a timer. In the timer callback function, I check whether a message from my hardware is received (I called it MSG_TOAM_TELL_STATUS). I answer that message and consider the connection as initialized.

But I never check the return value of hw_message_port_add(). Is it 0 or nil if not successful? Maybe I should wait in a loop for a good result.

Thank you
Detlef

User avatar
jph
Posts: 763
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: MessagePort USB problem

#6 Post by jph » Sat Apr 03, 2021 9:54 am

Hi Detlef,
Interesting. Simple answer to the return as to a successful connection is - I dont know.. :) That is an interesting one. Try it with a debug print. ? I Would be interested in the result. What you are using sounds correct to me.
I only did a simple test program with Message_Port quite a while ago and it worked fine. It was simply a proof of concept for future use.
I intent to use it for a huge amount of stuff later in my build as there are lots of custom arduino libraries I would like to use. - like the 'Accelstepper' library which is amazing and I want to use it for my instrument movements. I also have loads of custom displays and graphics modules etc. Anyway, that's another story.
I would be really interested in seeing some of your code as it would be a great help to me and I am sure I could learn a hell of a lot from the work you have done. I can send a pm if thats ok ?.

On the USB side, there is a nice utility that can monitor your usb connection for actual connect / disconnect errors. Windows Event manager is crap for this.
The util is USBLogView
http://www.nirsoft.net/utils/usb_log_view.html
“Everything in moderation, including moderation.”
“Experience is merely the name men gave to their mistakes.”
Joe (CISSP) -IT security consultant

Detlef
Posts: 122
Joined: Mon Nov 16, 2020 9:43 am
Location: Bavaria

Re: MessagePort USB problem

#7 Post by Detlef » Sat Apr 03, 2021 10:27 am

jph wrote:
Sat Apr 03, 2021 9:54 am
I would be really interested in seeing some of your code as it would be a great help to me and I am sure I could learn a hell of a lot from the work you have done. I can send a pm if thats ok ?.
Hi Joe,

I have no problem with sending my code. The problem is "some". The Arduino C code should be arround 3000 lines (I have not counted, it is several separate files), the Lua instrument code is close to 2000 lines. And I have written a Windows program that generates C code for initializing the pictures of my epaper displays, the data being in the program flash memory. The last one is really bad, me not all the time knowing what I do :oops: . I attach message.h and message.cpp here, don't know if that is interesting in any way. Many parts of my code deal with the display and its 20 LED equipped buttons. If you are interested in everything, I send it as PM. - The good thing is I give english names for everything just out of habit.
message.cpp
(6.52 KiB) Downloaded 55 times
message.h
(2.58 KiB) Downloaded 51 times
Thanks for the USB tool tip, I'll check that out next time the error happens.

Thank you
Detlef

User avatar
jph
Posts: 763
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: MessagePort USB problem

#8 Post by jph » Sat Apr 03, 2021 11:12 am

Detlef wrote:
Sat Apr 03, 2021 10:27 am
jph wrote:
Sat Apr 03, 2021 9:54 am
I would be really interested in seeing some of your code as it would be a great help to me and I am sure I could learn a hell of a lot from the work you have done. I can send a pm if thats ok ?.
Hi Joe,

I have no problem with sending my code. The problem is "some". The Arduino C code should be arround 3000 lines (I have not counted, it is several separate files), the Lua instrument code is close to 2000 lines. And I have written a Windows program that generates C code for initializing the pictures of my epaper displays, the data being in the program flash memory. The last one is really bad, me not all the time knowing what I do :oops: . I attach message.h and message.cpp here, don't know if that is interesting in any way. Many parts of my code deal with the display and its 20 LED equipped buttons. If you are interested in everything, I send it as PM. - The good thing is I give english names for everything just out of habit.

message.cppmessage.h

Thanks for the USB tool tip, I'll check that out next time the error happens.

Thank you
Detlef
Hi Detlef,
Huge thanks my friend,
I will send you a PM.
Joe
“Everything in moderation, including moderation.”
“Experience is merely the name men gave to their mistakes.”
Joe (CISSP) -IT security consultant

User avatar
jph
Posts: 763
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: MessagePort USB problem

#9 Post by jph » Sat Apr 03, 2021 11:15 am

Also Detlef,
Can I please ask which Epaper displays you are using ?
I hadn't consider those. Hmmmm. A backlit version would be really nice.
Joe.
“Everything in moderation, including moderation.”
“Experience is merely the name men gave to their mistakes.”
Joe (CISSP) -IT security consultant

User avatar
Ralph
Posts: 5164
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: MessagePort USB problem

#10 Post by Ralph » Sat Apr 03, 2021 12:10 pm

I did not ask for a box to check...

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests