MQX CDC virtual COM control signals

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MQX CDC virtual COM control signals

Jump to solution
1,132 Views
Hspahr_89north
Contributor II

I'm using the MQX CDC stack to emulate an RS232/virtual COM port to a host computer.  Data communication works great, but I want to send an indication to the host if my piece of equipment is being turned off.  Since the host computer is running a GUI written in Java, it only knows information about virtual COM port/RS232.  It doesn't know anything about the fact that the COM port is running over USB.  If I could emulate changing the control signals across the USB bus (such as setting the ring indicator, sending carrier detect/break character, or any control signal), the event could be caught on the host computer and the program could be gracefully shut down.  Does the MQX CDC stack support setting the controls signals?  Thanks in advance for any info.

Labels (1)
Tags (1)
0 Kudos
1 Solution
470 Views
Hspahr_89north
Contributor II

SET_CONTROL_LINE STATE is what I wanted.

 

I ended up using the following code:

 

  USB_SETUP_STRUCT          setupPkt;
  unsigned int                       size;

#define CLR_CARRIER_DETECT  0x00
 
  setupPkt.request_type = USB_REQUEST_CLASS_CLASS;
  setupPkt.request = SET_CONTROL_LINE_STATE;
  setupPkt.value = CLR_CARRIER_DETECT;
  setupPkt.index = 0;
  setupPkt.length = USB_SETUP_PKT_SIZE;
  (void)USB_CDC_Other_Requests(&setupPkt, NULL, &size,
    cdc_device_array[cdcHandle]);

I had to extern cdc_device_array because most CDC calls want the index to the device pointer instead of the device pointer.  This call wants the device pointer itself.  cdcHandle is the value returned from USB_Class_CDC_Init.

 

This code is useful if your application is Java and you are attaching to it using a virtual COM port.  Since Java doesn't know about the USB layer, you can change the carrier detect signal to indicate that the device has been removed.  This allows my application to cleanly exit instead of crashing java because the serial port has disappeared.

 

Thanks timias.  Your information got me on the right track.

View solution in original post

0 Kudos
3 Replies
470 Views
timias
Contributor IV

You might be able touse ioctl with SET_CONTROL_LINE_STATE or SEND_BREAK, not sure the parameters you will need to pas to them though

 

You could also send a software break command like an ETX character. There is a well establish protocol for that when using TCP, which you could mirror.

 

Can't you trigger an event when the serial port closes?

0 Kudos
471 Views
Hspahr_89north
Contributor II

SET_CONTROL_LINE STATE is what I wanted.

 

I ended up using the following code:

 

  USB_SETUP_STRUCT          setupPkt;
  unsigned int                       size;

#define CLR_CARRIER_DETECT  0x00
 
  setupPkt.request_type = USB_REQUEST_CLASS_CLASS;
  setupPkt.request = SET_CONTROL_LINE_STATE;
  setupPkt.value = CLR_CARRIER_DETECT;
  setupPkt.index = 0;
  setupPkt.length = USB_SETUP_PKT_SIZE;
  (void)USB_CDC_Other_Requests(&setupPkt, NULL, &size,
    cdc_device_array[cdcHandle]);

I had to extern cdc_device_array because most CDC calls want the index to the device pointer instead of the device pointer.  This call wants the device pointer itself.  cdcHandle is the value returned from USB_Class_CDC_Init.

 

This code is useful if your application is Java and you are attaching to it using a virtual COM port.  Since Java doesn't know about the USB layer, you can change the carrier detect signal to indicate that the device has been removed.  This allows my application to cleanly exit instead of crashing java because the serial port has disappeared.

 

Thanks timias.  Your information got me on the right track.

0 Kudos
470 Views
MarkW_
Contributor I

This is a bit off topic, but I noticed that you have achieved good virtual com port behavior in MQX.  I am having difficulty understanding how to make the virtual com port the default comm port for MQX rather than a UART.  I have the Kinetis-sc bare metal USB device demo working and I have other demos working running MQX, but haven't figured out how to merge the two.

 

Thanks.

 

0 Kudos