development of the serial port base class in the context of the
project. GA |
Request for Question Clarification by
mathtalk-ga
on
19 Feb 2004 20:02 PST
Thanks, Amy. I'm on it.
-- mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
20 Feb 2004 08:26 PST
Thank you
|
Clarification of Question by
amy123456-ga
on
24 Feb 2004 16:33 PST
Hi, GA
Hows are things coming along?
Thanks
|
Request for Question Clarification by
mathtalk-ga
on
24 Feb 2004 19:01 PST
Things are going smoothly. By the way, all the Google Answers
usernames end in "-ga"; even yours does.
regards, mathtalk!
|
Clarification of Question by
amy123456-ga
on
25 Feb 2004 03:10 PST
Sorry. I guess I should call you Mathtalk.
My apologies
Thank you
|
Request for Question Clarification by
mathtalk-ga
on
26 Feb 2004 20:04 PST
Hi, Amy:
Do you know which serial port we'll be using on the computer? For
example, is the World 1 box connected to COM1? COM2? or will it
perhaps be different on different machines?
regards, mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
27 Feb 2004 03:49 PST
COM1
|
Request for Question Clarification by
mathtalk-ga
on
27 Feb 2004 10:17 PST
Hi, Amy:
If you've not yet tried this, please download John Hind's project from:
[Use P/Invoke... for a Serial Communications Port]
http://msdn.microsoft.com/msdnmag/issues/02/10/netserialcomm/
I suggest using both Hyperterminal (the Windows applet) and the Base
Terminal application (an executable is included in the download) to
send characters through COM1 to the World 1 box.
This will help, for example, to identify permissions issues that might
arise in using the "unmanaged code" approach.
regards, mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
27 Feb 2004 12:28 PST
I Have loaded the application. and tested. I type in 001 and lights
7-14 are blinking and i can not stop it.
Help.
|
Request for Question Clarification by
mathtalk-ga
on
27 Feb 2004 13:36 PST
Hi, Amy:
One thing to keep in mind is that the World 1 codes are documented in
hexadecimal pairs. Thus when you "type" a 0 character, this amounts
to x30 rather than to x00 as one might expect.
If I remember correctly, the Base Terminal application provides for
hexadecimal entry by using an angle bracket "<" to open and ">" to
close. If you let the mouse hover over the text entry box, I think a
message appears that describes this.
regards, mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
27 Feb 2004 14:18 PST
I got it to stop.
Thank you
|
Clarification of Question by
amy123456-ga
on
01 Mar 2004 15:29 PST
Hi Mathtalk. I have tested and it works. the PC signs in as administrator.
|
Clarification of Question by
amy123456-ga
on
02 Mar 2004 13:49 PST
Hi Mathtalk. Any chance i can have something this week? They want to
kill the project, but i am holding on because i think this will be a
major advantage to both patient care and the administrative. Please
help
Thank you once again. Amy
|
Request for Question Clarification by
mathtalk-ga
on
02 Mar 2004 15:38 PST
Hi, Amy:
I'll leave work in about half an hour and post you some working code
tonight. I've been setting up a second machine to do serial port
testing on. Of course I can't duplicate the World 1 functionality,
but I wanted a more realistic test environment than my development
machine can provide.
regards, mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
02 Mar 2004 17:45 PST
Thank you so much.
|
Request for Question Clarification by
mathtalk-ga
on
03 Mar 2004 05:37 PST
Hi, Amy:
I spent way too much time last night with the configuration of my
second machine, and I don't have the complete project to give you yet.
But here are some steps to take to follow the progress.
Go to the downloaded C# project from John Hind's MSDN Magazine
article. If you haven't followed his instructions about loading the
source files from there into a C# Class Library project and recompiled
them, then you take these files from the download:
CommBase.dll
CommBase.xml
and place them in the bin/debug directory of the textextract project
that we've been working on. If you have recompiled the CommBase
project, as I have, then you will have essentially created new
versions of those files (possibly with a different name, depending on
how the Class Library project was named), and you can use them. The
CommBase.xml file here contains Intellisense information and is not
essential.
The next step is to add a reference to this new .Net component to the
existing textextract project. With the textextract C# project open in
Visual Studio .Net 2003, go to the Project menu and scroll down to the
Add References... item. This brings up a tabbed dialog that will
allow you to add a reference to the CommBase.dll component to your
project. There are a couple of ways to do this. I used the first
tab, which is labelled .Net. There's a big list of the "shared" .Net
components (the ones that Windows "knows" about) in the central
textbox, but we won't find CommBase.dll there since it has not been
"installed" as a shared component.
Instead hit the "Browse..." button and use the resulting Select
Component dialog to drill down to the bin/debug directory where you
put the CommBase.dll file (or whatever name it now has, if you've
recompiled it with a slightly different project name). Select the
file CommBase.dll and click the Open button. Focus now goes back to
the Add Reference dialog, where you'll see the CommBase.dll file (or
equivalent) listed in the bottom textbox (Selected Components). Click
the OK button.
You will now see the new component under References in the Project
tree of the Solution Explorer window in Visual Studio. If you right
click on it there and select the View in Object Browser item, then a
new view will open that allows you to navigate the interfaces of this
component (and any other references in the project, like System). I
mention this only in case Intellisense (Microsoft's name for the
"syntax prompting" that VS.Net does when you write code using
component methods) doesn't work for some reason; it can sometimes be
balky.
We have three "stubs" to fill in to the Switchbox code, now that the
serial port component is added to the project. The first of these is
the static MyInit() method, which currently has some lines that
represent the initialization of the World 1 box "outside" the
computer. Before those lines we want to add code that will intialize
the serial port to which the World 1 box is attached, ie. COM1 in your
case.
The simplest way to do this is probably a call like this:
public static void MyInit()
{
...
// initialize the serial port from "xml" stream s
JH.CommBase.CommBase.CommBaseSettings.LoadFromXML(s);
// set all ports & lines to write digital except 5,28,29
SerialWrite( Convert.ToByte( 0xfb ) );
...
in which we will load the serial port settings from an XML file. If
you remember your experiments with the BaseTerm executable, there's a
button on that application which says Settings. Clicking this brings
up a dialog that shows the port (COM1), the baud rate (19200), and the
DataBits/Parity/StopBits (8,none,1) which the World 1 box needs to
see. (Double check my memory on these as I don't have their
documentation in front of me, but it's spelled out in the information
you provided before.) The File menu on that dialog then allows you to
save those settings in an XML file, and we can then load those
"verified" settings into the textextract/Switchbox context.
The other two stubs that need to be filled in are the two SerialWrite
methods we defined in the Switchbox class. These differ in their
"signatures" (calling arguments:
static void SerialWrite(byte c)
static void SerialWrite(byte c, byte i)
The first of these is for writing one-byte commands, the second for
two-byte commands to World 1.
Where we "stubbed out" these methods with Console.WriteLine calls, now
we will instead have calls to:
JH.CommBase.CommBase.Send(byte)
or perhaps to JH.CommBase.CommBase.SendImmediate(byte). Perhaps if we
find that the program writes too many characters too quickly to the
port (faster than the World 1 box can read them), we will add calls
to:
JH.CommBase.CommBase.Sleep(int millisec)
just for the sake of slowing things down.
Hopefully this detailed outline of the few lines of code which need to
be added to the application give you a clear basis for confidence that
we can wrap things up this week. I apologize for not having tested
code to post at this point, but being "out on the road" adds a degree
of difficulty to my QA for your program.
Please try to save those serial port settings from BaseTerm which you
got to work with the World 1 box as an XML file, and post the contents
of that text file here.
regards, mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
03 Mar 2004 07:34 PST
Thank you.
I am going to try and see if i can follow the directions.
Thank you very much.
|
Request for Question Clarification by
mathtalk-ga
on
03 Mar 2004 21:35 PST
Hi, Amy:
I'm finding that the Send character calls are a bit tricky, because
they are defined as instance methods (not "static"). The call to load
configuration information was a class method (static), so this revised
start to the myInit() method compiles and should work fine:
public static void MyInit()
{
// initialize the serial port, throws exception if file DNE
FileStream s = new FileStream("world1.xml",FileMode.Open);
JH.CommBase.CommBaseSettings.LoadFromXML(s);
s.Close();
// set all ports & lines to write digital except 5,28,29
SerialWrite( Convert.ToByte( 0xfb ) );
...
Note that this bare bones code makes no attempt to catch the exception
that would get thrown if the configuration file world1.xml doesn't
exist (in the local or working directory). That's a detail we'll add
once the other critical pieces fall into place.
In order to call the Send(byte) method, we need to instantiate an
instance of a class derived from JH.CommBase.CommBase. In the sample
BaseTerm application, this is done by deriving class BaseTerm from
CommBase, and then instantiating BaseTerm. I believe we should do
exactly the same thing here, but it does kind of turn my mental
picture of these classes "inside out", so let me think about this a
little.
regards, mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
04 Mar 2004 17:19 PST
Thank you once again
|
Request for Question Clarification by
mathtalk-ga
on
05 Mar 2004 08:15 PST
Hi, Amy:
I was unable to stay up late last night as I needed to be in to work
early today. Will it be okay to post you the zipped up project files
tomorrow (on Saturday)?
regards, mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
05 Mar 2004 09:18 PST
Saturday night is OK.
PS- Could i ask a favor, Would it be possible to have the whole project
included with all the changes that we have made so far in the zip file.
Have a great weekend
Thank you so much MathTalk
|
Request for Question Clarification by
mathtalk-ga
on
05 Mar 2004 10:39 PST
Yes, that's where I think we need to go with this. The creation of
the "instance" of the serial port handler requires the program's
restructure in a way that would be hard to describe in sufficient
detail for you (or others) to follow. So I'm going to post the
complete program once it's rewritten, and also zip up the project
directory for the sake of convenience.
-- mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
05 Mar 2004 11:10 PST
Thank you, When i receive it, i will be able to work with it on
sunday and test it out before i bring it to work on monday.
Thank you very much once again.
|
Request for Question Clarification by
mathtalk-ga
on
07 Mar 2004 07:34 PST
Hi, Amy:
While I'm well-stock with espresso grind here at fortress mathtalk, I
need to run out for some scotch tape to put up my code diagrams. I'll
be online til we get this thing working once I return.
-- mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
07 Mar 2004 11:18 PST
I will get my coffee ready to.......
Thank you Mathtalk
|
Clarification of Question by
amy123456-ga
on
08 Mar 2004 08:59 PST
Hi MathTalk. No errors Greate. Question. The application is looking in
the folder for the file with the orders right?. what do we need to do
to make it read what ever file is in the folder requardles of file
name. If it could read and then be sent to another folder or deleted.
Thank you.
Command: 251
Port Cmd: 160 Bit Image: 47
Port Cmd: 176 Bit Image: 255
Port Cmd: 192 Bit Image: 63
Port Cmd: 208 Bit Image: 255
Port Cmd: 224 Bit Image: 1
Last name: COLEMAN
First name: EVELYN
Location: MS6
Room number: 11
Port Cmd: 177 Bit Image: 32
|
Clarification of Question by
amy123456-ga
on
08 Mar 2004 09:03 PST
Hi. Even though we openned the port, are we communicating with the wolrd1 yet?
Should a light be going on for this room #?
Thank you
|
Clarification of Question by
amy123456-ga
on
09 Mar 2004 11:20 PST
Hi MathTalk. I found a small problem with the rooms mapping.
The following list is an accurate mapping to rooms. Please note the problem is
with room 5 and port 5. I do not use port 5, but i do use port (E) 29 for room 5
Port Port # Code Room# Dec hex Bin
A 1 001 1 1 1 00000001
A 2 002 2 2 2 00000010
A 3 004 3 4 4 00000100
A 4 008 4 8 8 00001000
E 29 001 5 1 1 00000001
A 6 032 6 32 20 00100000
B 7 001 7 1 1 00000001
B 8 002 8 2 2 00000010
B 9 004 9 4 4 00000100
B 10 008 10 8 8 00001000
B 11 016 11 16 10 00010000
B 12 032 12 32 20 00100000
B 13 064 13 64 40 01000000
B 14 128 14 128 80 10000000
C 15 001 15 1 1 00000001
C 16 002 16 2 2 00000010
C 17 004 17 4 4 00000100
C 18 008 18 8 8 00001000
C 19 016 19 16 10 00010000
C 20 032 20 32 20 00100000
D 21 001 21 1 1 00000001
D 22 002 22 2 2 00000010
D 23 004 23 4 4 00000100
D 24 008 24 8 8 00001000
D 25 016 25 16 10 00010000
D 26 032 26 32 20 00100000
D 27 064 27 64 40 01000000
D 28 128 28 128 80 10000000
E 29 001 5 1 1 00000001
Thank you MathTalk
|
Request for Question Clarification by
mathtalk-ga
on
09 Mar 2004 12:33 PST
Amy, I know exactly what you are saying here. I had assumed that you
were simply shuffling all the rooms "down 1" after room 4. I'll fix
it up.
-- mathtalk
|
Clarification of Question by
amy123456-ga
on
09 Mar 2004 17:48 PST
Thank you MathTalk. I am sorry for being such a pain.!!!
|
Request for Question Clarification by
mathtalk-ga
on
09 Mar 2004 20:09 PST
Hi, Amy:
The lines that need to be changed are those in the static "class
constructor" for Switchbox, i.e. static Switchbox(). See my Comment
at the bottom of thread for details.
-- mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
10 Mar 2004 03:24 PST
Good morning mathTalk. The port does open, but the lights do not go on.
PS- To make sure the lights are working, i always test first with the world 1
interface. Then i will run the application to see if the lights will go
on, but they do not work with the application
Thank you very much for the mapping corrections.
|
Request for Question Clarification by
mathtalk-ga
on
10 Mar 2004 05:05 PST
Hi, Amy:
Probably the best starting point is to look at the console output for
the revised application, e.g. like you posted before for room number
11. We've changed the mapping, so now the final line should be
different. Double check that the values in the console output
correspond to the documented commands for the World 1 interface.
There is a possibility that the baud rate is not being set correctly.
One way to check this would be to connect a second PC to the same
serial port, using what's called a null modem cable. By setting the
second PC to the expected settings (baud rate 19200, 8 data bits/no
parity/1 stop bit) using Hyperterminal, you should be able to see the
same number of characters appear in the second PC as are sent by the
first PC (running our application).
If these tests are successful, then we may need to "slow down" the
sending of data. In other words even though the baud rate is being set
successfully, perhaps the World 1 interface cannot really follow along
at the advertised rate and we would need to introduce some delay
between sending bytes. (A second PC would certainly be able to handle
the character transmission at the advertised rate.)
regards, mathtalk-ga
|
Request for Question Clarification by
mathtalk-ga
on
10 Mar 2004 05:08 PST
Another diagnostic tool is the BaseTerm application, which should
allow you to load the very same worldcomm.xml settings we use and
verify that you can enter the World 1 instructions "by hand".
-- mathtalk-ga
|
Request for Question Clarification by
mathtalk-ga
on
10 Mar 2004 05:38 PST
One more idea... You say you use the World 1 interface to turn lights
on. I'm not quite sure what this means, but perhaps you could leave
the lights on, then verify that when the "patient orders" application
initializes the "switchbox", all the lights go out. That would be a
result of the resetting command (which puts all the lines into digital
read mode), and it would indicate that at least the first command byte
we send is being read.
As a simple way of "slowing down" the interface, you can run the
program under the Visual Studio debugger. Stepping through the
program would certainly give the World 1 hardware plenty of extra time
to respond to the bytes we are sending.
-- mathtalk-ga
|
Request for Question Clarification by
mathtalk-ga
on
10 Mar 2004 07:42 PST
Note that the PC to World 1 cable, according to their documentation,
is a straight-thru cable, not a null modem cable. The null modem
cable crosses over certain pairs of pins (depending on whether a
25-pin or 9-pin setup is used).
See here for details:
[Wiring a Null Modem Cable]
http://www.loop-back.com/null-mod.html
Of course you won't need to wire one up yourself; you can pick one up
cheaply at a local electronics store. Conceptually the null modem
cable tricks both PC's into thinking they are each connected to a
modem, when actually neither one is.
-- mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
10 Mar 2004 08:09 PST
I turn on all the lights with the world one, i exit world one and
start our application and run and all the lights go off.
|
Clarification of Question by
amy123456-ga
on
10 Mar 2004 08:30 PST
Hi.
I found the following when i openned the xml file.
<member name="F:JH.CommBase.CommBase.CommBaseSettings.port">
<summary>Port Name (default: "COM1:")</summary>
</member>
- <member name="F:JH.CommBase.CommBase.CommBaseSettings.baudRate">
<summary>Baud Rate (default: 2400) unsupported rates will throw "Bad
settings"</summary>
</member>
- <member name="F:JH.CommBase.CommBase.CommBaseSettings.parity">
<summary>The parity checking scheme (default: none)</summary>
</member>
- <member name="F:JH.CommBase.CommBase.CommBaseSettings.dataBits">
<summary>Number of databits 1..8 (default: 8) unsupported values
will throw "Bad settings"</summary>
</member>
- <member name="F:JH.CommBase.CommBase.CommBaseSettings.stopBits">
<summary>Number of stop bits (default: one)</summary>
|
Clarification of Question by
amy123456-ga
on
10 Mar 2004 09:03 PST
Hi. The last XML i sent you was the combase.xml.
the following is the worldcom.xml.
<?xml version="1.0" ?>
- <CommBaseTermSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<port>COM1:</port>
<baudRate>19200</baudRate>
<parity>none</parity>
<dataBits>8</dataBits>
<stopBits>one</stopBits>
<txFlowCTS>false</txFlowCTS>
<txFlowDSR>false</txFlowDSR>
<txFlowX>false</txFlowX>
<txWhenRxXoff>true</txWhenRxXoff>
<rxGateDSR>false</rxGateDSR>
<rxFlowX>false</rxFlowX>
<useRTS>none</useRTS>
<useDTR>none</useDTR>
<XonChar>DC1</XonChar>
<XoffChar>DC3</XoffChar>
<rxHighWater>0</rxHighWater>
<rxLowWater>0</rxLowWater>
<sendTimeoutMultiplier>0</sendTimeoutMultiplier>
<sendTimeoutConstant>0</sendTimeoutConstant>
<rxQueue>0</rxQueue>
<txQueue>0</txQueue>
<autoReopen>false</autoReopen>
<checkAllSends>true</checkAllSends>
<showAsHex>false</showAsHex>
<breakLineOnChar>false</breakLineOnChar>
<lineBreakChar>NULL</lineBreakChar>
<charsInLine>0</charsInLine>
</CommBaseTermSettings>
I have three file-- the commBasesource.dll and commBase.xml and worldcomm.xml. all
under. textextract\textexttract1\bin\Debug folder
Is that the right placement for them
|
Request for Question Clarification by
mathtalk-ga
on
10 Mar 2004 09:42 PST
Hi, Amy:
Yes, I believe that is the correct directory for them. You can
actually step through the program with the debugger and verify that it
is opening the worldcomm.xml file as the settings for
CommBaseTermSettings.
Since it did successfully turn off the lights, I suspect the problem
is speed, ie. the PC sending characters too quickly for the World 1
interface to absorb. A good way to verify this is to step through the
program in the debugger, because the added delay in executing the
calls to Send( ), if you step down into the SendChar( ) routine, will
provide any amount of delay that could be needed. A simple approach
would be to set a breakpoint early in the SendChar( ) routine in the
WorldComm helper class. That way you can just let the program
"continue" without a lot of tedious decisions about Step Into or Step
Over. The program will automatically break right before making the
Send( ) call.
regards, mathtalk-ga
|
Request for Question Clarification by
mathtalk-ga
on
10 Mar 2004 09:54 PST
It turns out I mapped some of the hexidecimal values incorrectly.
Take the port A configuration for example:
Port Cmd: 160 Bit Image: 47
First we send ASCII 160 = xA0, followed by ASCII 47 = x2F.
The last value makes it pretty clear. The lowest four bits are set,
which I thought makes those lines digital write, and also the sixth
bit. We skip over the fifth bit because it is not used.
But I just checked the documentation at the website:
http://www.ccielectronics.com/worldman.html#anchor286012
and it's 1 for "input" (read), 0 for "output" (write).
I need to go through and change the corresponding bits on those
configuration bytes.
sorry 'bout that,
mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
10 Mar 2004 10:14 PST
Hi. I spoke to the tech dept at world one.
I told them what was happening, i would turn all lights on with the
world1 and then exit out. Go to our application and run the code and
it would turn off the lights but not turn on the room # that it found.
I then went back to the world1
and started the world1 and set the direction to output and the room #
that our application had found would now light up.
Thank you
|
Request for Question Clarification by
mathtalk-ga
on
10 Mar 2004 10:51 PST
Hi, Amy:
Find these lines in the orders.cs file:
// set all ports & lines to write digital except 5,28,29
SerialWrite( Convert.ToByte( 0xfb ) );
SerialWrite( (byte) 0xa0, (byte) 0x2f );
SerialWrite( (byte) 0xb0, (byte) 0xff );
SerialWrite( (byte) 0xc0, (byte) 0x3f );
SerialWrite( (byte) 0xd0, (byte) 0xff );
SerialWrite( (byte) 0xe0, (byte) 0x01 );
and replace them with these:
// set all ports & lines to write digital except 5
SerialWrite( Convert.ToByte( 0xfb ) );
SerialWrite( (byte) 0xa0, (byte) 0x10 );
SerialWrite( (byte) 0xb0, (byte) 0x00 );
SerialWrite( (byte) 0xc0, (byte) 0x00 );
SerialWrite( (byte) 0xd0, (byte) 0x00 );
SerialWrite( (byte) 0xe0, (byte) 0x00 );
That should correct the problem, making the direction output (write)
on all lines except 5.
regards, mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
10 Mar 2004 12:41 PST
Hi. All the lights go on now, and and when i run it the second time,
the lights do not go off.
All lights go on now. I am sending you a copy of the console
Command: 251
Port Cmd: 160 Bit Image: 16
Port Cmd: 176 Bit Image: 0
Port Cmd: 192 Bit Image: 0
Port Cmd: 208 Bit Image: 0
Port Cmd: 224 Bit Image: 0
Last name: COPATHCCMC2
First name: BUELAH
Location: MS6
Room number: 03
Port Cmd: 161 Bit Image: 4
Thank you MathTalk- I am so sorry for causing so much problems.
|
Request for Question Clarification by
mathtalk-ga
on
10 Mar 2004 13:48 PST
Thanks, Amy, glad to hear it works. We can discuss the logic for
turning lights off when you want.
-- mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
10 Mar 2004 14:35 PST
Hi. MathTalk, I think you misunderstood me. When i mention that all
the lights go on, i meant that they all go on at the same time.
Sorry - Thank you
|
Request for Question Clarification by
mathtalk-ga
on
10 Mar 2004 19:48 PST
My, I did misunderstand, didn't I. Running the program in the
debugger will either pin down where the lights get turned on (and I
think I might have an idea about this), or else it will turn out the
problem doesn't occur when the program runs through the debugger.
I highly recommend learning how to use the debugger. I may sound
complicated but you will quickly get the hang of things.
Let me think about the symptoms while I put together a debugging
tutorial as a Comment below.
regards, mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
11 Mar 2004 03:51 PST
Good morning MathTalk. Look at the console print out.
the images are all 0's
Command: 251
Port Cmd: 160 Bit Image: 16
Port Cmd: 176 Bit Image: 0
Port Cmd: 192 Bit Image: 0
Port Cmd: 208 Bit Image: 0
Port Cmd: 224 Bit Image: 0
Last name: COPATHCCMC2
First name: BUELAH
Location: MS6
Room number: 03
Port Cmd: 161 Bit Image: 4
Thank you
|
Clarification of Question by
amy123456-ga
on
11 Mar 2004 04:04 PST
Hi Again. Let me understand something here. Every time the program runs it
sets the ports to digital and direction to output, right?
This is what is happenning, Every line below as the program runs
through turn on each group (A, B, C, D, E)
so when the last group is finished all the ligts are on.
// set all ports & lines to write digital except 5
SerialWrite( Convert.ToByte( 0xfb ) );
SerialWrite( (byte) 0xa0, (byte) 0x10 );
SerialWrite( (byte) 0xb0, (byte) 0x00 );
SerialWrite( (byte) 0xc0, (byte) 0x00 );
SerialWrite( (byte) 0xd0, (byte) 0x00 );
SerialWrite( (byte) 0xe0, (byte) 0x00 );
Thank you.
|
Request for Question Clarification by
mathtalk-ga
on
11 Mar 2004 06:29 PST
Well, the intention is to set the lines' direction to digital output,
but not necessarily to turn output to on, if that makes sense.
A digital write (output) line can be either off or on. I assumed that
the reset command as documented sets the direction to digital input
but also puts the line levels to off. It may be that the digital
lines can "remember" a state of being turned on. So one test we can
do is to include in our initialization a step of explicitly turning
all the lines off (after setting them to output). However we throw
information away when we do that!
It's kind of nice that the World 1 box might remember the on/off
status of the lines, independent of whether the program is running.
It might be necessary to stop and restart the program, for example,
and if by default the World 1 box remains lit in the same fashion as
before, we might design around that. Of course it probably makes
sense at some point to keep a database of the states of lights and
reinitialize all the lights at program startup using that.
Let's try adding some code that explicitly sets the output lines to
off, right after configuring the lines for digital write (output).
One way to do this is to loop through the room numbers, calling
Lampset with false (to turn the light for that room number off).
-- mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
11 Mar 2004 08:40 PST
Good morning MathTalk. I got it to work. I added the following code to
each port. I write to the port first and then set to output.
SerialWrite( (byte) 0xa1, (byte) 0x10 );
SerialWrite( Convert.ToByte( 0xfb ) );
SerialWrite( (byte) 0xa1, (byte) 0x10 );
SerialWrite( (byte) 0xa0, (byte) 0x10 );
SerialWrite( (byte) 0xb1, (byte) 0x10 );
SerialWrite( (byte) 0xb0, (byte) 0x00 );
SerialWrite( (byte) 0xc1, (byte) 0x10 );
SerialWrite( (byte) 0xc0, (byte) 0x00 );
SerialWrite( (byte) 0xd1, (byte) 0x10 );
SerialWrite( (byte) 0xd0, (byte) 0x00 );
SerialWrite( (byte) 0xe1, (byte) 0x10 );
SerialWrite( (byte) 0xe0, (byte) 0x00 );
Your hints and suggestions help me brain storm and i tried and it worked.
Thank you once again
|
Clarification of Question by
amy123456-ga
on
11 Mar 2004 09:02 PST
Hi. The lights work. the problem now is that when ever the program
runs it turns off the lights that were on. The lights need to stay on
until a staff members acknowledges and turns them off.
Thank you
|
Request for Question Clarification by
mathtalk-ga
on
11 Mar 2004 09:07 PST
Nice work! As you say, you are actually writing the on/off level
_before_ turning the I/O direction to write. It makes me wonder if
the "default" effect of resetting the lines (to digital read) is to
silently set all the bits to "on". This doesn't sound like a great
design decision though, and perhaps another explanation is that having
the lights all turned on was a side-effect of what you'd done directly
with the World 1 interface previously.
At any rate, congratulations on getting your hands "dirty" with the
code and on exercising the serial port further. At this point I feel
pretty confident that we don't have a "speed" problem.
regards, mathtalk-ga
|
Request for Question Clarification by
mathtalk-ga
on
11 Mar 2004 10:30 PST
Hi, Amy... we must have been composing those last two msgs at the same time!
Here's my thought about the management of the lights, esp. preserving
the on/off state. First we could think about keeping the program
running "all the time", which of course is an ideal that is never
really attained. But it ties in with having the program running in a
loop, looking for new files to parse, which is the subject we will
(quickly) tackle on your other Question.
Second, we should find out exactly what needs to be done to preserve
the state of the lights from one program invocation to the next. We
should try commenting out the lines you added and running the program
again, just to verify whether that "all lights on" was an artifact of
the first command (resetting the ports) or of the experiments done
with the World 1 interface earlier. Given that it is truly an
unfortunate conseqeuence of the reset command, however dubious that
might be in terms of their design, I think we able to work around the
problem by adding a command line parameter to the program. The idea
would be to either do the serial port initialization pretty much the
way you are now, turning "down" all lines explicitly, or to skip the
part of the initialization that involves World 1 commands altogether.
Basically we'd just initialize the serial port itself and then proceed
to write commands to the World 1 box.
Third we could save the settings of the lights into a database
("persist the state of the Switchbox class") when the program shuts
down, and then explicitly reapply those settings at the next run.
We may find that some combination of these ideas is necessary to
provide the best solution.
We will also need to discuss the management of the lights' on/off
behavior sometime soon. The current application never takes the
responsibility for turning a light off, although a function to do that
is implemented, and also an occasion might arise when a patient order
comes in while another is pending and the light is turned on "twice".
You have probably given this some thought but we not discussed it. If
one order is fulfilled in such a case, but one is still outstanding,
we presumably want the light to stay on. That would be consistent
with the outcome if the two orders for the same patient did not happen
to overlap in execution.
The design decision is then, who/what is responsible for managing the
multiple orders that apply to a single room number. If the nurse is
in charge, then it would simply be a matter of his or her checking
that all orders are done before the light is turned off. If the
application were responsible for managing this, it would need to keep
a count of orders applied and discharged, and the nurse would have to
signal once for each order fulfilled.
Give this some thought and let me know what you'd like to do next.
regards, mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
11 Mar 2004 11:29 PST
Hi. I did comment out the lines that i added and ran the program.All
the lights went on. I added the lines back to the program and ran the
program and the light that needed to go on worked.
1- What about a separate program to just initializa the world1 state.
a-write to port-turn off lights
b-Assign port direction - output
2- Management of lights. their will be situations where one pt will
have more than one order coming in. all we want the staff to know is
that, the pt she is caring for has orders, and she needs to verify on
the application (Sunrice clinical managers) the actual orders for this
patient. Maybe we can have a user interface with all the room #'s
displayed. The nurse would then click on the room # that she needs to
turn off the light, it would prompt her for her NOVELL PW and User
name, a message would appear stating that by clicking ok she
acknowlodges that she viewed the patients actual orders in (sunrise
clinical manager). Maybe we can create a log with the user name time
and date so we can track.
3-Nursing will be totally responsable for turning the lights off. The
reason for this approch is that we want to monitor how long it will
take for an order
to be viewed by an nurse after it is written. Everyone on the unit
will know that a patient in room 2 for example has orders, Because of
the light being on. Everyone will help police the time factor.
|
Request for Question Clarification by
mathtalk-ga
on
11 Mar 2004 11:56 PST
1. Okay, that sounds like a nice solution. As an experiment, trying
commenting out all the SerialWrite commands in the MyInit() method.
See if running the program without them produces the expected
behavior, i.e. preserves the light settings. A robust implementation
will require that we actually read the state of all the digital lines
during initialization (to populate the pimg array). I'll try my hand
at this tonight.
2. This would be easiest to implement if the machine the nurses use to
turn the lights out is the same as the one which automates turning
them on. In fact we can provide both functions in the same program,
although it wouldn't necessarily have to be arranged that way.
Effectively the nurse turning a light off would need to update a bit
state stored in the pimg[] part of the Switchbox class (the same bit
state we will need to read and remember above).
I'm not sure if you'd want to use the Novell user ID and password to
validate a user. User validation is always tricky, but turnkey
point-of-sale systems generally require users to have a separate
"code" that identifies them, to "open" a cash register. I understand
the function of logging/monitoring compliance, but human factors are
involved. You want to encourage pride in a job well done, not
cheating to avoid perceived penalization.
3. The lights will certainly help someone who needs a quick idea if
there are orders outstanding, but because some orders go unfulfilled
because of outside factors, e.g. meds not being delivered yet, it will
not be obvious to onlookers how appropriate group policing might be.
A comparison might be drawn with patient call buttons, where typically
the fulfillment is more completely controlled by the nursing staff
than with physicians' orders.
regards, mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
11 Mar 2004 12:32 PST
Hi. Nursing will be turning off the lights on the same PC as the program will run.
Thank you
|
Clarification of Question by
amy123456-ga
on
11 Mar 2004 12:48 PST
PS- Every unit will have one PC running the application, Both to turn On /Off
Commenting out. no errors, the light just did not go on
/*SerialWrite( Convert.ToByte( 0xfb ) );
SerialWrite( (byte) 0xa1, (byte) 0x00 );
SerialWrite( (byte) 0xa0, (byte) 0x00 );
SerialWrite( (byte) 0xb1, (byte) 0x00 );
SerialWrite( (byte) 0xb0, (byte) 0x00 );
SerialWrite( (byte) 0xc1, (byte) 0x00 );
SerialWrite( (byte) 0xc0, (byte) 0x00 );
SerialWrite( (byte) 0xd1, (byte) 0x00 );
SerialWrite( (byte) 0xd0, (byte) 0x00 );
SerialWrite( (byte) 0xe1, (byte) 0x00 );
SerialWrite( (byte) 0xe0, (byte) 0x00 );*/
console print out results
Last name: COPATHCCMC2
First name: BUELAH
Location: MS6
Room number: 03
Port Cmd: 161 Bit Image: 4
|
Request for Question Clarification by
mathtalk-ga
on
11 Mar 2004 13:40 PST
Hmm... that's discouraging!
Well, in the worst case we will have to preserve and reinstate the
light settings from within the program, which is not a bad approach
(because we ideally want all the on/off operations to be logged
through the program anyway).
I'll go ahead and bundle all the static data members for Switchbox
into an instance of a nested "helper" class Map. The Map state can
then be serialized out to an XML file just as we do with the
CommBaseTermSettings configuration. We can then save it on closing
and reload it on initialization.
regards, mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
11 Mar 2004 14:55 PST
sounds like a good idea.
Thank you very much for your assistance today
|
Request for Question Clarification by
mathtalk-ga
on
13 Mar 2004 10:34 PST
Hi, Amy:
To update you on my progress, I moved the Switchbox static data
members port[], line[], pimg[], and pcmd[] into a nested "helper"
class, WorldMap, and in their place created a static member of
Switchbox wmap, which is an instance of WorldMap.
I made the necessary prefixes to existing references to these data
elements, like wmap.port[..], and recompiled.
I need to "refactor" the initialization of those data elements, which
(to the extent it was done before) took place in the Switchbox class
constructor. That code needs to be moved into the static method
Switchbox.MyInit(s), where (by analogy with the loading of
"persistent" WorldComm settings) we will load from worldmap.xml those
settings if this file exists; otherwise do the existing "from scratch"
initialization. Code must also be added to Switchbox.MyClose() which
handles writing the current WorldMap state out to that specific file.
The code immediately below the comment "// set all ports & lines ..."
will then have to be rewritten to take advantage of our wmap object,
so that any previous on/off light settings are restored.
regards, mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
13 Mar 2004 16:34 PST
Thank you mathtalk
|
Request for Question Clarification by
mathtalk-ga
on
14 Mar 2004 19:23 PST
Hi, Amy:
I updated and tested the textextract project with revisions pertaining
to the "helper" class WorldMap nested inside Switchbox.
In addition to creating the static method for loading a WorldMap
instance from an XML file and a (non-static) method for saving a
WorldMap instance back to XML (and calling these respectively during
the Switchbox "type initializer" (class constructor) and the
Switchbox.MyClose() methods), I've added another byte array to hold
the directional information for the digital lines and restructured the
World 1 initialization code to take advantage of this (it's a for loop
now, instead of a repetitious block of code).
The "mapping" of World 1 ports and their settings are saved out to a
file called worldmap.xml in the "local" directory each time the
program closes. If you delete the file, then it prints a message and
initializes using the "all lights off" settings. Thus the default
behavior is to preserve the light settings from run to run, but if you
want to reset all lights to off, then you stop the program and delete
the worldmap.xml file to force a clean slate. The design is not
completely clean because both mapping of rooms to ports and on/off
settings of lights are combined in one configuration file, but it will
be serviceable as long as the port mapping doesn't change.
I also added a bit of exception handling around the code that opens
the serial communications port itself. If you come across situations
in which the program ends abruptly with an unhandled exception, make a
note as it could be a clue that additional try/catch handling would
help.
Use the same download link as before:
http://68.15.21.151/uploads/researchers/switchbox.zip
regards, mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
15 Mar 2004 11:07 PST
Hi Mathtalk. It works very nicely. no errors.
I have tried lots rooms and they all go on and the others stay on. i
also played with the worldmap.xml by deleting it and i was able to see
what you said.
it rebuilds another worldmap.xml with new settings.
Thank you very much once again.
PS. How difficult will it be to create the user interface to shut the lights off.
|
Request for Question Clarification by
mathtalk-ga
on
15 Mar 2004 15:23 PST
Hi, Amy:
I have a "cheesy" idea about how to make that function ride on the
back of this program, using basically a simple second program that
will allow users to create text files, in the same directory as the
"printer" files, that connote an instruction to turn a light off.
However, we need to get on with the looping through that directory in
any case, so what say we close down this Question and meet over there?
regards, mathtalk-ga
|
Clarification of Question by
amy123456-ga
on
15 Mar 2004 17:06 PST
Ok.
|