Question about using USB-Serial SP vs USB-Serial Modules

@ kgcode -

[quote]GHI.Usb.Client.Controller::set_ActiveDevice
GHI.Usb.Client.RawDevice::Activate
GHI.Usb.Client.RawDevice::NativeInitialize[/quote]

How do you see these exceptions while you don’t have USB Serial module?

Did you put switch 4th in Serial debug mode?

1 Like

I think you forgot to push the switch 4 to serial debug mode.

1 Like

@ Dat -

Thanks for your reply. Yes, that was it. I got so focused on the code, I neglected the switch. Sorry for not catching this.

A quick follow-up question…where would I find documentation for reading the state of the mainboard switches (specifically, #4 on the Spider), so that I can programmatically flash an error LED if the switch is found to be in the incorrect position?

Thanks again.

@ kgcode -

Code is simple, just copy the example code, deploy it into your spider, put switch #4 is ON, switch 1,2,3# are OFF, then Reset the board. 99,9% there should be new COM port under your DM.

When switch #4 is on, USB port that connected to PC is changed to other function (here is VCOM), not for debugging any more. You may need USB serial module if want to debug in this mode.

About how to set these switches 1,2,3,4 , you can open FEZ Config → select advance → Update Tinybooter-> Spider. When you click few Next, there is an image, at the bottom of image, you will see another button like “see more image…”. There are some images that tell you more detail how to set these switches.

These switches are located close to the RESET button. Default all should be in OFF.

@ Dat -

Thanks for your reply.

Yes, I realize that. I had no trouble locating or setting the switches properly. What I was missing before, with the switches in the correct position, was that the code on the device had to actually execute before the device would be recognized as a serial port. Then, when you pointed out that I needed to run the code to get the module in the right mode, I forgot to deal with setting the switch properly. A case of my brain only dealing with one thing at a time, I guess. It worked just fine once I got the switch set after deploying the code.

I had been confused by my misunderstanding of someone’s earlier post that seemed to imply that the two Windows devices (USB client and virtual COM port, both on the USB Client SP module) would be seen by Windows simultaneously. When I realized that they are mutually exclusive, things started falling into place.

I had no trouble locating or setting the switches properly. Just had trouble getting the right sequence of deploy, change switch, restart, and getting the proper Windows driver to load - that required sequence had been tripping me up. It makes so much more sense, now that I’ve gotten it to work.

Regarding my follow-up question: I’d like to have my code programmatically read the state of switch #4 at runtime (and flash an error LED or send a message to an attached display), so that I can quickly catch the “switch is in the wrong position again” situation in the future. Where would I find documentation on how to programmatically read the position of switch #4 on the Spider?

Thanks again.

@ andre.m -

Thanks for your reply.

Yes, the schematic shows IO71 connected to switch #4. And I know how to set up and read a socket pin, but I’m (still very new at this and) don’t yet know how to properly set up reading a mainboard pin.

I suspect I would use new InputPort((Cpu.Pin)71,… but am unsure what the remaining constructor argument should be in this situation. Once the port object is created, I would issue a Read() to get the boolean value.

So, to be more specific, what should the additional InputPort constructor arguments be when reading pin 71 of the Spider? Or, if I am on the wrong track, what is the correct track?

Thanks.

@ andre.m -

Thanks for your reply.

Yes, I had read through that Digital Inputs document already, but unfortunately I don’t yet know enough about hardware to know what the values for the glitch filter and resistor mode should be in the arguments to the InputPort constructor in this specific case. The schematic shows that this particular dip switch is connected to a resistor which is connected to +5V, but I don’t know how to translate that into the appropriate constructor arguments.

My uneducated guess would be that the glitch filter argument should be false on a dip switch. My uneducated guess for the ResistorMode argument would be PullDown, since the pin, when the switch is OFF, isn’t connected to anything. I could experiment, but I don’t want to do any harm (and frankly don’t know if I could do any harm) if I use an incorrect argument value.

So, to be specific, for reading this particular dip switch value on CPU pin 71 (which when ON connects to the pin to a resistor and +5V and when OFF doesn’t connect the pin to anything), what should be the second and third arguments sent to the InputPort constructor?

Thanks.

Using my uneducated guesses (above) and newfound courage, I attempted the following and it seems to work.


// ...
InputPort dipSwitch4 = new InputPort((Cpu.Pin)71, false, Port.ResistorMode.PullDown);
// ...
if (dipSwitch4.Read())
{
    displayTE35.SimpleGraphics.DisplayText(
         "Switch #4 is ON.", font, color, 0, 0);
}
else
{
    displayTE35.SimpleGraphics.DisplayText(
        "Switch #4 is OFF.", font, color, 0, 0);
}

But, I’d still like to know for sure if these constructor arguments are the best ones for this particular situation.

Thanks.

@ kgcode -

I think your code is right :slight_smile: