Vb to Slc

garryt1

Member
Join Date
Jun 2002
Location
n.ireland
Posts
128
Hi there,

I know a little !! about vb but i have quite a lot of experience with plc's,i am trying to write a small hmi application for alarms between a slc 5/04 and a vb gui.I know how to get the data into the vb but if i want to read individual bits i cannot get my head around this.I can use automatedsolutuions eth or dh+ active x down to bit control but the rslinx help file does not go into this detail.
I am using RsLinx Pro,can somebody please guide me on this topic.

thanks in advance.

Garry bloody frustrated T!
 
use some variable as integer (16 bit) and use them.
Alam_Int = Alarm_int or 1 ' sets bit 0 where is some alarm bit
Alam_Int = Alarm_int and 0 ' resets bit 0
Alarm_Bit_0_Bool = Alam_Int and 1 ' retrun True if true
Alarm_Bit_2_bool = Alam_Int and 4 ' retrun False if False
 
Sorry, mistake !!
Alam_Int = Alarm_int or 4 ' sets bit 2

Alam_Int = Alarm_int or 4 ' 1'st sets bit 2 (just in case)
Alam_Int = Alarm_int xor 4 ' 2'nd resets bit 2
 
'...if you intend to do a lot of programming with bits, then do it in hex.

Dim PLCword as long
Dim result as boolean

'....isolate individual bits
result = PLCword And &H0001 '....result contains bit 0
result = PLCword And &H0002 '....result contains bit 1
result = PLCword And &H0004 '....result contains bit 2
result = PLCword And &H0008 '....result contains bit 3
result = PLCword And &H0010 '....result contains bit 4
etc. etc.
result = PLCword And &H8000 '....result contains bit 15


'....test individual bits for truth
If result then '...test result for true
If PLCword and &H0001 then '...test the bit in the word directly

'....test individual bits for false
If Not result then '...test result for false
If Not (PLCword and &H0001) then '...test the bit in the word directly


'....setting bits within a word to 1
PLCword = PLCword Or &H0001 '....set bit 0 true
PLCword = PLCword Or &H0002 '....set bit 1 true
PLCword = PLCword Or &H0004 '....set bit 2 true
PLCword = PLCword Or &H0008 '....set bit 3 true
PLCword = PLCword Or &H0010 '....set bit 4 true
'...etc. etc.
PLCword = PLCword Or &H8000 '....set bit 15 true


'....reset (set to 0) a bit within a word by inverting the bits in the appropriate nibble
PLCword = PLCword AND &HFFFE '....reset bit 0 to false (1110b)
PLCword = PLCword AND &HFFFD '....reset bit 1 to false (1101b)
PLCword = PLCword AND &HFFFB '....reset bit 2 to false (1011b)
PLCword = PLCword AND &HFFF7 '....reset bit 3 to false (0111b)
PLCword = PLCword AND &HFFEF '....reset bit 4 to false (1110b)
'...etc. etc.
PLCword = PLCword AND &H7FFF '....reset bit 15 to false(0111)

Learn Hex nibbles and the inverse of same and you'll have it made.
 
Thanks guys!

this is great,

however what i mean is ,say i read a word O:4/0,L16(RsLogix500) into a text box txtBlock(0)or maybe an array ,what i see in the text box is the following 0||0||1||0||.... and so on,how do i individually reference these bits for reading as alarm bits???

thanks in advance
 
parse the DDE data

When using DDE you should start by learning as much as possible about the DDE's different operational modes. This being a Microsoft app
it is well documented. You should move all data into continous
files in the PLC. Say n7:1 to n7:100. Read them all at once.
Don't try to read different types of data and individual files. Do the same thing when you write the data into the PLC.
This improves the communication efficiencies. The DDE commands allow you to organize the data as CF_text with different format.
Select the number of columns and amount of white space that makes the
most sense for your app. Write a routine that parses the data from
the text box into a string array. Use above described techniques to
manipulate individual bits.
If you have plenty of horse power in your PLC you may wanna consider
using a whole N file just for one bit, this will make programming easier.
If you decide to use OPC you can specify boolean type and read
and write the bits directly. This is where OPC shines.
If you are a novice programmer DDE will be a lot easier to use.
 

Similar Topics

I'm trying to read/write to an SLC5 with a ControlLogix L71 V35 plc that fails. The exact same code works on an L82S with V32. Is there a known...
Replies
9
Views
88
I'm ashamed to admit this but I've never had to replace a battery in a SLC. Some how been able to skip that task in all my years. So yesterday...
Replies
8
Views
214
I have a program that I've used 100 times. SQO settings: File N7:0, Mask 0FFFFh, Dest B3:1, Control R6:0, Length 8, Pos 2. Length & Position...
Replies
48
Views
793
Hello PLC friends. I've been going through a saga of diagnosing and fixing an old PLC setup that I inherited. I am learning as I go. Initial...
Replies
14
Views
298
I had a 5/01 CPU give a CPU Fault. It lost the program and I was not able to establish communication with it. I replaced it with a 5/03 we had in...
Replies
3
Views
111
Back
Top Bottom