RS232/RS485

  • Soweit ich das verstanden habe lässt sich beispielsweise für COM2 über den Registryeintrag RTS_CONTROL_TOGGLE die Funktionalität der Schnittstelle zwischen RS232 und RS485 umschalten.


    Meine Frage hierzu ist:
    Lässt sich das auch während des Betriebs umschalten oder muss die PicoMod neu gebootet werden? Hintergrund ist, dass wir gerne sowohl RS232 als auch RS485 über die gleiche Busche bereitstellen möchten und der Benutzer die Funktionalität einfach umschalten kann.

  • You don't need to reboot the PicoCOM to get the configuration changes working. You can use DeactiveDevice ActiveDevice to re-initiate the serial driver.
    Please refere to the MSDN page for more details: ActivateDevice reference

    Software developer, F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Can you please give me an example of using ActivateDevice and DeactivateDevice in C#?


    Function declaration (in class DeviceHandle):

    Code
    1. [DllImport("coredll.dll", EntryPoint = "ActivateDevice", SetLastError = true)]
    2. public static extern IntPtr ActivateDevice(
    3. string lpszDevKey,
    4. Int16 dwClientInfo);


    When I call the function with:

    Code
    1. IntPtr handle = DeviceHandle.ActivateDevice(@"Drivers\BuiltIn\Serial3", 0);
    2. int error = DeviceHandle.GetLastError();


    handle is Zero and error code is 87.

  • Error code 87 means "invalid parameter" (-> Windows CE error codes)


    Please try to open it with:

    Code
    1. IntPtr handle = DeviceHandle.ActivateDevice(L"Drivers\\BuiltIn\\Serial3", 0);

    Software developer, F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hello Mr. Kiepfer,


    for what does the L" stands for? I can't use this in C#


    WhenI try to run this function while the driver is already active, I get error code 2404 (ERROR_DEVICE_IN_USE)

  • The L" is used in C++ to instruct the compiler that the following string should be a wide-charachter string. In C# all strings are wide-characters automatically I suppose. So you don't need the L.


    Quote from "Festus"

    When try to run this function while the driver is already active, I get error code 2404 (ERROR_DEVICE_IN_USE)


    It looks like another application is still using COM3. Are you sure that this isn't the case. Maybe you have configured NDCUCFG to run on COM3.

    Software developer, F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • I only get Error 2404 when I try to activate the driver and the driver is already active (listed under Drivers\Active registry key). I'm able to deactivate the driver with DeactivateDevice(Handle) and after calling this function, the driver is removed from Drivers\Active.


    When I try to activate the driver after I have deacivated it using the Function DeactivateDevice(HANDLE) then I get the error 87.


    I also have tested the syntax by deacivating and activating the digital IO driver by simplay replacing "Serial2" with "DIGITALIO" and that workes without any problem ( the only thing is that after reactivating the driver there is a missing registry entry in Drivers\Active\XX\ named BusParent?!

  • Quote from "Festus"

    I only get Error 2404 when I try to activate the driver and the driver is already active (listed under Drivers\Active registry key). I'm able to deactivate the driver with DeactivateDevice(Handle) and after calling this function, the driver is removed from Drivers\Active.


    This behaviour seems to be correct for me. If a device is activated already it will not be allowed to activate the device again.


    Quote from "Festus"

    When I try to activate the driver after I have deacivated it using the Function DeactivateDevice(HANDLE) then I get the error 87.


    To activate the device you must use the ActiveDevice function. Maybe this was a mistake in writing?


    To to re-initialize a driver you must first deactivate it and then activate it again. This should also be able for the serial driver.
    Could you please post some more example code?

    Software developer, F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • OK I have a form with two button, one for Activation, obe for Deactivation. De Activation/Deactivation is performed in the buttons Click event.



    The class DeviceHandle contains PInvoke functions:



    There is no problem with deactivation. When I click btnDeactivate, I get the correct handle with FindDevice("COM2") and I can deactivate the driver with DeactivateDevice(handle). After deactivation the registry entry of COM2 is removed from "Drivers\Active" and if I click btnDeactivation again, I get error 18 (ERROR_NO_MORE_FILES).


    So I should be able to reactivate the driver again when I click btnActivate but the IntPtr is zero and I get error 87 when I click it.


    I have no problems when I try the same with digitalIO driver. When I replace "Serial2" with "DIGITALIO" and "COM2" with "DIO1" the digital IO driver can be deactivated and activated without problem.

  • The same problem occurs when I try it with C++. I'm not 100% familiar with C++ but the functions seems to be correct. Deactivation works, Activation works not. When I change "Serial2" to "DIGITALIO" and "COM2" to "DIO1", it works...


  • You are right. We have tested reactivating the serial driver and the debug line we notices that the serial driver throws an exception. There seems to be a bug in the serial driver.
    We will fix this in the next kernel release.

    Software developer, F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Sounds good. Can you tell me when the new kernel will be available?
    Another issue concerning kernel update: Please read my post in the thread Kernel update. I have trouble with kernel update in PicoMOD3.