1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[Solved] Triggering RelayOn From Windows Service

Discussion in 'Relay Modules' started by rickd, Apr 17, 2015.

Thread Status:
Not open for further replies.
  1. rickd

    rickd New Member

    Joined:
    Apr 17, 2015
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Georgia
    Hello - I am trying to actuate the relay via a windows service that is running. I am able to use the sample code I downloaded and turn the relay on/off. The driver is installed and indicates in Device Manager that the 1 channel USB relay module is on Com3. In my service,
    First I open the port
    if (!_serialPort.IsOpen)
    {
    _serialPort.PortName ="COM3"
    _serialPort.BaudRate = 9600;
    _serialPort.Open;
    }

    then
    _serialPort.DiscardInBuffer();

    if (!_serialPort.IsOpen)
    and write to the port with
    _serialPort.Write("relay on 0\r")

    The account in serviceProcessInstaller is set to Local System.

    Does anyone have an idea on why the relay does not actuate?

    Thanks,

    RD
     
  2. admin

    admin Administrator Staff Member

    Joined:
    Jan 23, 2015
    Messages:
    169
    Likes Received:
    11
    Trophy Points:
    18
    Hello Rick,

    Most probably the culprit is hardware/software handshake. Can you please try setting it to "None" or equivalent ? In some cases, handshaking is turned off by default. But there are cases too where it has to be done explicitly.

    Hope this helps, if not we will do some further debugging for sure.

    Thanks,
    Tom
     
  3. rickd

    rickd New Member

    Joined:
    Apr 17, 2015
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Georgia
    Hello Tom - I'll try your suggestion. I have developed a console application that is compiled into an .exe file. This app works and flip-flops the relay when it's clicked. I used the same code in my windows service but it seems not to find the port.
    I'll let you know how it works out.


    regards,

    Rick
     
  4. rickd

    rickd New Member

    Joined:
    Apr 17, 2015
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Georgia
    Hello Tom - I was able to turn on the relay via the web service. It was not a handshake issue. Rather it was a variable scope issue causing the problem.
    Thanks,

    Rick
     
  5. admin

    admin Administrator Staff Member

    Joined:
    Jan 23, 2015
    Messages:
    169
    Likes Received:
    11
    Trophy Points:
    18
    Hello Rick, happy to hear that your were able to sort out the issue.

    Cheers,
    Tom
     
Thread Status:
Not open for further replies.

Share This Page