SetCommMask() ERROR Invalid argument (22)


I have an application that uses relays to control AC Contactors (coil is 120v) and they seem to work for sometime. After running my sketch with the relays, several times, I get disconnection from the serial port. The following continuous message appear on the command prompt of the serial connection:

SetCommMask() ERROR Invalid argument (22)

If I close the serial command prompt window (containing the serial connection) and run again the Cayenne-ser.bat batch file, it starts working again for sometime and then I get the same error. Have you seen this before? Not sure if it started after one of the Windows updates…


@adam @eptak tagging for this.


Sorry, I have only used the serial connection method a few times. May I ask why you are using it? It’s meant more for testing/debugging than to be a “production” solution.


Hi Adam,

I’m using a Latte Panda board, which is a Windows 10 Home computer with a built-in Arduino Leonardo. The board has Wireless and Ethernet ports, but they “belong” or can be seen by the Windows 10 OS. As far as I know, using the serial connection is the only way to connect to the Cayenne Portal. The Latte Panda has like a “virtual” serial port connection for the built-in Arduino Leonardo. That is the reason I’m using the serial connection.


I guess it really depends on what you’re trying to do and at what level. I don’t have a LattePanda so I’m not quite sure how it works or what sensors/devices you are using and how they are connected. Are you able to get everything you need through the windows 10 OS? If so, you can use a program/script in the Windows 10 OS to send the data using the MQTT API.


Hi Adam,

Just to let you know that it seems I found what was causing the issue. Between reading and contacting the relay supplier, we were able to narrow the problem to induction noise. I bought two induction suppression caps and the SetCommMask() error disappear!


Thanks for posting back!