Home AMX User Forum AMX Technical Discussion
Options

programmatically emulate receiving from serial device?

I've been using the Emulate a Device panel a lot lately and I'd like to just put some code into my mainline to automate my testing a little.

I naively tried:
DEFINE_PROGRAM
WAIT 30 { send_string 5001:1:0 , "'R123',13" }

but nothing showed up at my data event.

Is this possible?

Comments

  • Options
    shr00m-dewshr00m-dew Posts: 394
    Pretty sure that will only send data to the device you are controlling. Since you are emulating a device, I imagine you wanted that string to appear to come into the port, not go out.

    I don't know of a way to simulate this with code (could very well be possible). But if you are using a buffer to parse the data, you could just assign the string to the end of the buffer. But you would have to parse in mainline as no Data_Event would be generated.

    If not, you could loop the TX pin to the RX pin of the com port and use the code you have. AMX will send the string out the TX port which will immediately come back into the RX port.

    Kevin D.
  • Options
    travistravis Posts: 180
    shr00m-dew wrote: »
    I imagine you wanted that string to appear to come into the port, not go out.
    Right. D'oh.
    I don't know of a way to simulate this with code (could very well be possible). But if you are using a buffer to parse the data, you could just assign the string to the end of the buffer. But you would have to parse in mainline as no Data_Event would be generated.
    I hope it's possible. I want to test my actual Data_Event code. If I could do this, I could write a bunch of elaborate tests, and then when I plugged in the actual sensors, they would Just Work.
    If not, you could loop the TX pin to the RX pin of the com port and use the code you have. AMX will send the string out the TX port which will immediately come back into the RX port.
    Kevin D.
    I'd try this, but I don't have any actual hardware handy.
    I guess we could also write some serial port emulator program outside of netlinx.

    thanks
  • Options
    HedbergHedberg Posts: 671
    You can connect two of your master's serial ports together and program the second serial port to act like the device you want to control.
  • Options
    Another way may be to use a virtual device for testing. Instead of a physical port (i.e. 5001:1:0) create and use a virtual device (i.e. 33001:1:0). If you now do a SEND_STRING to the virtual device, you will get the string from the virtual device immediately.

    But keep in mind that this may not be the "real world" ;)
  • Options
    GSLogicGSLogic Posts: 562
    Make a cross cable (2 to 3 : 3 to 2) from one rs232 port to an other.
    send_string 5001:1:0, 'test';   //port 1 loop to port 2
    
    data_event[5001:2;0]
    {
        string: send_string 0, "data.text";
    }
    
    Or you could just use a virtual.
  • Options
    travistravis Posts: 180
    Another way may be to use a virtual device for testing. Instead of a physical port (i.e. 5001:1:0) create and use a virtual device (i.e. 33001:1:0). If you now do a SEND_STRING to the virtual device, you will get the string from the virtual device immediately.

    But keep in mind that this may not be the "real world" ;)

    This works and I only had to change a few things that can easily be changed back for the real sensors.
    DEFINE_DEVICE
    dvVirtual = 33001:1:0
    dvVirtual2 = 33002:1:0
    dvVirtual3 = 33003:1:0
    
    DEFINE_VARIABLE
    DEV Virtuals[3] = {dvVirtual, dvVirtual2, dvVirtual3}
    
    DEFINE_EVENT
    DATA_EVENT [ Virtuals ] {	
    	STRING:{
    		x = data.device.number - 33000
    		// do stuff depending on which device caused the event
    		}
    	}
    
    Define Program 
    	Wait 20 r_num = RANDOM_NUMBER(25); send_string dvVirtual, "ITOA(r_num),13"
    	Wait 20 r_num = RANDOM_NUMBER(25); send_string dvVirtual1, "ITOA(r_num),13"
    	Wait 20 r_num = RANDOM_NUMBER(25); send_string dvVirtual2, "ITOA(r_num),13"
    
    
    Right now I'm trying to figure out the right way to to nest the waits so they will happen in order, 2 seconds apart...
    Edit: using a timeline now. Works well. Awkward to set up though.

    Thanks, guys!
Sign In or Register to comment.