This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28377D: ERROR 304: "Unable to modify COM port state" Using C2000gang.dll InitCom function

Part Number: TMS320F28377D
Other Parts Discussed in Thread: MSP-GANG, C2000-GANG

I am doing production programming using the C200gang programmer from Elpotronics and using the associated library C200gang.dll.

I never have a problem using the C2000 gang GUI.  Using the DLL, I can program once.  Then when I run InitCom again, I get ERROR 304: Unable to modify COM port state.  I'm setting to 115200, and COM2 is the correct port.  I am using ReleaseCom function once I am done calling the DLL the first time.  If I ignore the error, I get error 306 which is another com port error.

I usually can unplug and and plug in the USB (Virtual Com Port) and then get it to work again but sometimes it takes a few tries.

  • Hi Greg,

    The GUI using the same C2000gang.dll what you are using in your application. If you have no problem with GUI than means - C2000gang.dll is OK. When you call InitCom function then the USB port is assigned to your application. Calling again that function will fail, because port is already used. You cannot can that function again if you do not release the port. In your application the InitCom can be used only once. 

    Let me know if you have any questions.

    Regards,
    Gregory Czajkowski
    Elprotronic Inc.

  • Hi,

    How exactly do you release the port?  Isn't it just the ReleseCom function?  These are the steps I'm doing.  The second time I run the sequence it fails on InitCom.  If it fails with that error code, should I call ReleaseCom, even though I think it should have already been done?

    C2000GANG_InitCom

    C2000GANG_Default_Config

    C2000GANG_SetConfig.

    C2000GANG_GetConfig

    C2000GANG_Set_MCU_Name

    C2000GANG_Read_Code_File

    C2000GANG_SetConfig

    C2000GANG_Read_Code_File   (Again for the second core)

    C2000GANG_CreateGangImage

    C2000GANG_InteractiveProcess

    C2000GANG_GetProgressStatus

    C2000GANG_ReleaseCom

  • I checked the software - the ReleaseCom is even used at the beginning of the InitCom if software detect that the port is already open. But looks that you are closing dll before the port is released. Question - why you are opening and closing the USB port every time? Sometimes it takes more time then other procedures do. The InitCom should be used once. Before you are opening the port you should scan available ports using
    C2000GANG_HW_devices( MAX_COM_NO, (void **) &AvailableComPorts ); and do not try to open the port that is not on the list. That function also help you find if the port is already open and is busy - you can not use it again.
  • I am doing that sequence once on each production board. For the next board I repeat the process. How should I properly "release and close the DLL"?

    I could look into using that function. I still don't know what I will do if the com port is not on the list. And I think I have noticed this behavior using the GUI. I've had to unplug and reconnect the USB cable to the programmer sometimes several times, for MSP-GANG CDC device to show and turn green in the bottom right. I wonder if there's a way to get windows 10 to refresh the USB or Virtual COM ports?
    Greg
  • Hi Greg,
    Are you using C2000-Gang.lib or using opening the dll via opening instance and LoadLibrary( ...dll file)? Sequence is related to the method you used for accessing the dll. The MSP-GANG GUI is using C2000-Gang.lib, but it can be used option with LoadLibrary( ...dll file) if more than one programmer is connected to application.
    Do you really need to open and closed dll every time you are accessing the target device? It takes extra time. Do you need to loose every time the startup time?
    Gregory
  • I'm using the "Call library function node" in LabVIEW 2017. Just calling into C2000-Gang.dll.
    Also I sometimes get Error 66: CSM unlock error. But I am still releasing the COM port after an error occurs. Do you know of a fix for that?

    When I say "sequence" I just mean calling that list of functions.
    Also I have another programmer, so I plugged in the other one after that error occurred (rather than just unplugging the reconnecting the same device as I have been when this occurs), and I got the same 304 error, so I'm pretty sure its not a hardware problem.
  • You have an examples how to use the dll in directory
    C:\Program Files (x86)\Texas Instruments\C2000-GANG\Examples
    That examples using the C2000-Gang.lib. If you are using LoadLibrary, then make sure that you ReleaseCom and free the library (dll) at the end. That should release the Com Port.
    Gregory
  • Hi,

    This is resolved. I moved the C2000 gang programmer to a direct USB port (not going through a hub) and now its working much better.

    Thank you.

    Greg