Hi,
I've got a query regarding memory array and sharing between sequences running in seperate threads.
I'd like to have Sequence1 putting data into an array, and Sequence2 pulling it out ie FIFO. I was thinking of implementing a fifo array with head and tail indexes where the "putting" sequence uses the head and the "pulling" sequence uses the tail index.
1. Is it safe to use the arrays like this, are they thread-safe?
2. I haven't seen a builtin "fifo" structure so will have to implement in code which I've done many times but not in DF. Do you have any tips/pitfalls to watch out for?
Background info
My application involves pulling data from a remote TCP device, putting a time stamp on it and putting it into an array, for another sequence to process. I need the putting seq to be fast since it's the one putting time stamps on incoming data and I want them to be as real time as possible. The processing sequence does a bunch of sorting, processing and manipulating then stores the required data to file, so this can be a bit slower. Currently I'm using a basic semaphore flag to control which sequence gets access, however I don't think it's the most effective way since it means the putting sequence may have to wait for the processing sequence to relinquish the flag.
Regards
Andrew
- AzeoTech Forum
- → Viewing Profile: Topics: andrewjfox
andrewjfox
Member Since 10 Jun 2010Offline Last Active Jan 15 2013 01:50 AM
Community Stats
- Group Members
- Active Posts 70
- Profile Views 1390
- Member Title Member
- Age Age Unknown
- Birthday Birthday Unknown
-
Gender
Male
Contact Information
0
Neutral
User Tools
Friends
andrewjfox hasn't added any friends yet.
Latest Visitors
Topics I've Started
Array Shared Between Sequences
14 January 2013 - 07:54 PM
Comm Objects
29 August 2012 - 11:12 PM
Hi ,
I've been using objects for ports and devices in an existing project but am still getting some behaviour which I don't understand
I am trying to close and -reopen a ethernet connection as follows
//Instatiate objects, and open connections
// functions to open & close connections
When I call the CloseConnection function I get an error at the InitComm() function
CloseConnection(0)
C1000 Channel or function not found: CloseConnection Line 15: Line 1
My understanding is that the InitComm() call should be successful regardless of whether connection is open /closed. Do you have any ideas for me to try?
Also I tried including the port object in my device object
class DeviceObj
local iDevice
local RxBuff
local State
function OnCreate()
iDevice = new(CCommDevice)
State = DEVICE_STATE_CLOSED
endfunction
endclass
Regards
Andrew
I've been using objects for ports and devices in an existing project but am still getting some behaviour which I don't understand
I am trying to close and -reopen a ethernet connection as follows
//Instatiate objects, and open connections
define CTRL_PORT = 0 define RADIO_PORT = 1 class DeviceObj local iDevice local RxBuff local State function OnCreate() iDevice = new(CCommDevice) State = DEVICE_STATE_CLOSED endfunction endclass global MyDevice global MyPort for(private i=0,i<MAX_READERS,i++) MyPort[i*2 + CTRL_PORT] = new(CCommEthernet) MyDevice[i*2 + CTRL_PORT] = new(DeviceObj) MyPort[i*2 + RADIO_PORT] = new(CCommEthernet) MyDevice[i*2 + RADIO_PORT] = new(DeviceObj) OpenConnection(i) endfor
// functions to open & close connections
function OpenConnection(ReaderIndex)
private pDevice
private pPort
try
pDevice = MyDevice[ReaderIndex*2 + CTRL_PORT]
if(pDevice.State == DEVICE_STATE_CLOSED)
pPort = MyPort[ReaderIndex*2 + CTRL_PORT]
pPort.Address = strAddressBase + DoubleToStr(DeviceAddress[ReaderIndex])
pPort.Port = CPORT
pPort.Timeout = 1000
pDevice.iDevice.PortObject = MyPort[ReaderIndex*2 + CTRL_PORT]
pDevice.iDevice.ProtocolName = "NULL Protocol"
pDevice.iDevice.InitComm()
pDevice.State = DEVICE_STATE_OPEN
endif
pDevice = MyDevice[ReaderIndex*2 + RADIO_PORT]
if(pDevice.State == DEVICE_STATE_CLOSED)
pPort = MyPort[ReaderIndex*2 + RADIO_PORT]
pPort.Address = strAddressBase + DoubleToStr(DeviceAddress[ReaderIndex])
pPort.Port = RPORT
pPort.Timeout = 1000
pDevice.iDevice.PortObject = MyPort[ReaderIndex*2 + RADIO_PORT]
pDevice.iDevice.ProtocolName = "NULL Protocol"
pDevice.iDevice.InitComm()
pDevice.State = DEVICE_STATE_OPEN
endif
catch()
Event.AddValue(Format("Error: Rdr%02d, ",ReaderIndex)+strLastError)
endcatch
endfunction
function CloseConnection(ReaderIndex)
private pDevice
private pPort
//try
pDevice = MyDevice[ReaderIndex*2 + CTRL_PORT]
pPort = MyPort[ReaderIndex*2 + CTRL_PORT]
pPort.Address = ""
pPort.Port = 0
pDevice.iDevice.PortObject = MyPort[ReaderIndex*2 + CTRL_PORT]
pDevice.iDevice.InitComm()
pDevice.State = DEVICE_STATE_CLOSED
pDevice = MyDevice[ReaderIndex*2 + RADIO_PORT]
pPort = MyPort[ReaderIndex*2 + RADIO_PORT]
pPort.Address = ""
pPort.Port = 0
pDevice.iDevice.PortObject = MyPort[ReaderIndex*2 + RADIO_PORT]
pDevice.iDevice.InitComm()
pDevice.State = DEVICE_STATE_CLOSED
//catch()
// Event.AddValue(Format("Error: Rdr%02d, ",ReaderIndex)+strLastError)
//endcatch
endfunction
When I call the CloseConnection function I get an error at the InitComm() function
CloseConnection(0)
C1000 Channel or function not found: CloseConnection Line 15: Line 1
My understanding is that the InitComm() call should be successful regardless of whether connection is open /closed. Do you have any ideas for me to try?
Also I tried including the port object in my device object
class DeviceObj
local iDevice
local RxBuff
local State
function OnCreate()
iDevice = new(CCommDevice)
State = DEVICE_STATE_CLOSED
endfunction
endclass
Regards
Andrew
Variable AddValue vs Variable[0]
09 August 2012 - 07:06 AM
Hi,
I'm having some trouble with the various data types. Although variables, channels and vchannels work similarly (in theory) I'm finding certain subtle differences and can't get the right type for what I want.
application:
I'm storing arrays as they come in over a network to a variable for later processing.
eg
Data.AddValue({{128,1,3,5,7}})
Data.AddValue({{129,2,4,6,8}})
Data = {{129,2,4,6,8},{128,1,3,5,7}}
then in processing loop the code looks for data with bit 7 set (data dirty bit) in first element, and clears this bit when data has been processed.
The processing loop also uses the timestamp of each array, Data.Time[0], as part of the processing
Problem:
- If Data is V type, then AddValue sets the time of all previously added arrays in history to the same value, so I can't use the timestamps to process the data
- If Data is channel, then trying to change an existing value (Data[0][0]) is the same as AddValue, so adds new entry with incorrect data, instead of changing the existing data at [0][0]
- If data is variable then, again, trying to change a single element Data[0][0] stuffs up the entire history
I'd like to be able to add arrays to a channel/variable, and be able to go through the history and change individual elements. Is this possible using the functions AddValue etc, or do I need to manually manipulate a standard array? I only want a history of about 100 arrays
Regards
Andrew
I'm having some trouble with the various data types. Although variables, channels and vchannels work similarly (in theory) I'm finding certain subtle differences and can't get the right type for what I want.
application:
I'm storing arrays as they come in over a network to a variable for later processing.
eg
Data.AddValue({{128,1,3,5,7}})
Data.AddValue({{129,2,4,6,8}})
Data = {{129,2,4,6,8},{128,1,3,5,7}}
then in processing loop the code looks for data with bit 7 set (data dirty bit) in first element, and clears this bit when data has been processed.
if(TestBit(Data[0][0],7)) Data[0][0] = ClearBit(Data[0][0],7) // do some processing on Data endif
The processing loop also uses the timestamp of each array, Data.Time[0], as part of the processing
Problem:
- If Data is V type, then AddValue sets the time of all previously added arrays in history to the same value, so I can't use the timestamps to process the data
- If Data is channel, then trying to change an existing value (Data[0][0]) is the same as AddValue, so adds new entry with incorrect data, instead of changing the existing data at [0][0]
- If data is variable then, again, trying to change a single element Data[0][0] stuffs up the entire history
I'd like to be able to add arrays to a channel/variable, and be able to go through the history and change individual elements. Is this possible using the functions AddValue etc, or do I need to manually manipulate a standard array? I only want a history of about 100 arrays
Regards
Andrew
- AzeoTech Forum
- → Viewing Profile: Topics: andrewjfox
- Privacy Policy


Find content