Page 1 of 1

Serial Simulation

Posted: Fri Apr 29, 2022 2:25 am
by alanwms
I have success with my serial RS232 comms, but don't seem to be able to inject data at simulation time.

How much stuff do I have to go through in order to allow me to inject a serial string?

I did search around, but came up empty. Used to be easy in FC7 era.

Re: Serial Simulation

Posted: Fri Apr 29, 2022 9:11 am
by medelec35
Hi
Injectors have been removed with V9, so now you don't have to add additional injector components to receive data.
Here are my properties to receive injected data:
I used the attached flowchart to send the data to the target device then the send part was disabled.

Re: Serial Simulation

Posted: Fri Apr 29, 2022 10:22 pm
by alanwms
I want to type in a string "B11021000" from my keyboard while in simulation and have the simulator accept it as a receive function.

Re: Serial Simulation

Posted: Fri Apr 29, 2022 11:13 pm
by mnfisher
One way to do this (and I'm sure there must be an easier one....) is to use a virtual com port.

For example - I used the free trial from https://www.eltima.com/virtual-com-port-windows-10/
Then I create a pair of com ports (I had 13 -> 14) and connect FC Data source com port to 14... (it takes some time for the ports to show up if FC is running whilst they are created)
Then open 'putty' (or your favourite terminal program) on COM13 Then you can type whatever to the simulation com port (note that this step isn't required if the receive program is running on an MCU - as you can connect directly using 'putty')

The problem here is that the eltima software is expensive (there is a 14 day free trial). There are other virtual serial port programs available (some free) - though I haven't tried them.

Note that the 'logic' of the sample above means that the string received must be received in 10ms (so type fast) - or change the timeout on the ReceiveString function - or receive the data to a buffer and look for a 'termination' character (newline or no. characters received etc)

Martin

Re: Serial Simulation

Posted: Fri Apr 29, 2022 11:22 pm
by mnfisher
I feel it should be possible to use the COM / File injector API components (under API) though my small trial didn't work with either....

Martin

Re: Serial Simulation

Posted: Fri Apr 29, 2022 11:36 pm
by medelec35
With the attached Flowchart, you can type into the Human Interface RX Queue of the Console, while the simulation is running.
The LCD will show the chars as you are typing.

Re: Serial Simulation

Posted: Sat Apr 30, 2022 8:45 am
by chipfryer27
Hi Martin

If I'm not mistaken I think they're referring to FC not being able to simulate a Receive Interrupt.

Having used this interrupt many times to populate the CB I'm quite familiar with it and know it works (at least in my applications). In simulation, if an Injector could directly populate the CB then that would negate any need for an Interrupt to do so and would maybe be quite an easy component / feature to include?

Whilst learning about the CB I used to include a push button that was polled in the main loop. If pressed (simulating my interrupt) it would branch and populate the CB with whatever test string I chose. The main loop (which polled the CB) would then react. My test string(s) would include junk messages and of course the proper one(s) too thereby ensuring correct "polling" of the CB.

Regards

Re: Serial Simulation

Posted: Sat Apr 30, 2022 11:20 am
by medelec35
Hi
The Flowchart I posted was only to work with simulation, not hardware.
I just wanted to establish if entering data on the console was what Alan was after.
If it was then I would then create a flowchart that works in simulation and hardware.
It would use an RX interrupt, circular buffer & LCD control.
For example, send

Code: Select all

#
and the LCD is cleared.
Send

Code: Select all

;
and the chars are printed on the next row of the LCD.

I have now decided the flowchart would come in handy as it works with both simulation and hardware, So I have uploaded it.
The secret is to use IsSim component to enable a timer interrupt within simulation only.
The timer interrupt will call the RX interrupt macro.
It's important the timer interrupt does not call the RX interrupt macro on hardware.
In simulation mode the characters are entered within the Human Interface RX Queue of the Console
What I have noticed is you need to click on the blank area of the Human Interface RX Queue once, enter the char and then click on the blank area for the second time.
You then should be good to keep typing chars from your keyboard.
As soon as you type a char, it will disappear as it is being received within the CB via RX ISR user macro.