|
このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。 |
Click here if you want to know more about the source and 判型 of these pages.
This page is "browser friendly". Make your browser window as wide as you want it. The text will flow nicely for you. It is easier to read in a 狭くする window. With most browsers, 圧力(をかける)ing 加える, minus or 無 while the 支配(する)/統制する 重要な (ctrl) is held 負かす/撃墜する will change the texts size. (大きくする, 減ずる, 回復する to default, それぞれ.) (This is more fully explained, and there's another tip, at my 力/強力にする Browsing page.)
Most of this page is about 令状ing programs. If you (機の)カム here to collect a program for reading from the PCSensor.com TEMPerLAN, 恐れる not! Just download the TCP001 zip とじ込み/提出する. In it you should find TCP001.exe. That's all you need! Save that. It is the "finished program", not a 体制/機構 とじ込み/提出する. Run it, fill in the "port" (probably 5200 will be 権利 for you) and "server" (警察などへの)密告,告訴(状), and all should be 井戸/弁護士席. (You put your TEMPerLAN's IP 演説(する)/住所 in the "server" box.)
The .zip とじ込み/提出する also has a とじ込み/提出する called TCP002.exe. That is a better 使用/適用... it is an 高めるd TCP001. TCP002 is for people who have a TEMPerLAN, and want to be able to 接近 it across the web, or want to have readings taken at a different interval than the once- per- second which is all the ソフトウェア 供給(する)d with the TEMPerLAN in September 2011, as far as I could see.
The .zip とじ込み/提出する also has an 使用/適用 called TCP003.exe. This is a 天然のまま simulator of a TEMPerLAN with three sensors. The first two always 報告(する)/憶測 16.06 degrees C and 31.87 degrees C. The third sensor 報告(する)/憶測s 気温s from 16.06 degrees C to 31.87 degrees C, and the 気温 報告(する)/憶測d changes once per second. It goes up by one sixteenth of a degree Celsius. After the 気温 reaches 31.87, it 減少(する)s 支援する to 16.06 again.
The TEMPerLAN simulator was developed from the ICS デモ "TcpSrv". (Not to be 混乱させるd with "SrvTcp"!) It isn't 100% reliable, but seems to work, mostly! (If you are having trouble when using the TEMPerLAN simulator (TCP003) to run through the tutorial, start shutting 負かす/撃墜する both server (TCP003) and (弁護士の)依頼人 each time you 改訂する the (弁護士の)依頼人. 再開する the server before you 再開する the (弁護士の)依頼人.(They can both be on the same machine.)
At first ちらりと見ること, this might seem to be a tutorial of little 利益/興味 even to the admittedly small universe of programmers 利益/興味d in TCP/IP. It 会談 a 広大な/多数の/重要な 取引,協定 about communicating with a TEMPerLAN, which few of you will have.
恐れる not! While you need a TEMPerLAN, or Arduino (or other) clone... that's something I hope I can get arranged, by the way... to 現実に do the 演習s here, the topics covered are of enormous general significance to anyone trying to work with TCP/IP... some of the most 根底となる 問題/発行するs are 調査するd. You won't be able to work with web page servers (be it making servers or (弁護士の)依頼人s), won't be able to do email programming, etc, etc, without a しっかり掴む of the 問題/発行するs covered here, which are part of the 創立/基礎s of those more exalted activities. By the way: not every server is serving HTML.
For the sake of a pretty picture, here's what the 使用/適用 developed in this tutorial looks like, when reading (across the LAN) from a TEMPerLAN with three 気温 sensors 大(公)使館員d. It was reading at one reading every two seconds. Can you see which sensor I had just しっかり掴むd in a warm 手渡す? Not how the rise decelerates as the 気温 of the sensor approaches that of the 手渡す.

A 収集するd .exe とじ込み/提出する for that can be downloaded. It is part of the .zip とじ込み/提出する which 含む/封じ込めるs all of the sourcecode for the 使用/適用. It was written using Delph7 and the Internet 構成要素 控訴 (ICS) by Francois Piette and associates.
Some things to keep in mind as you work through this 構成要素...
The ソフトウェア it 述べるs makes a PC a (弁護士の)依頼人 for the TEMPerLAN (or 同等(の)). Putting that another way: we are going to 令状 (弁護士の)依頼人 ソフトウェア. And the TEMPerLAN, as you may have guessed, is a server in all of what follows.
There is nothing 始める,決める in 石/投石する about what a (弁護士の)依頼人 sends to a server, nor in whether it 答える/応じるs at all, nor in how it 答える/応じるs, when it does, when you are working with IP/TCP at this level. I will give you the 詳細(に述べる)s of what the TEMPerLAN will 答える/応じる to. (That dictates what the (弁護士の)依頼人 should send!) And I will tell you how the server 答える/応じるs when it 答える/応じるs... which 決定するs how you 令状 the "陳列する,発揮する the answer" parts of the program. But all of that is "詳細(に述べる)"; it is all just a distraction. Necessary distraction, yes... but don't let it distract you from the basic 原則s 存在 illustrated here.
Once you have mastered those basic 原則s, you can go on to working with web servers, and other (弁護士の)依頼人/ server 状況/情勢s. In those 状況/情勢s, 確かな 支配するs do 適用する about what is sent by the (弁護士の)依頼人, how the server 答える/応じるs. But until you can do a basic, "解放する/自由な form" send, until you can read SOMETHING coming 支援する, you aren't ready for the next 問題/発行するs, are you? This 熟考する/考慮する of the TEMPerLAN will get you there!
The TEMPerLAN is a neat little 装置 from PCSensor.com. You plug 1-Wire 気温 sensors, which are Good People, into one 味方する, and then you plug the other 味方する into your LAN, and Presto!, you can see the 気温s the sensors are seeing. That's the theory.
As I said, even if you don't have a TEMPerLAN, the ideas in this discussion of 接近ing a TEMPerLAN may be useful. I can think of plenty of 類似の 装置s you could create with an Arduino with an ethernet 保護物,者, for instance. (Cost of 金物類/武器類? As low as $40.) A LAN interface for the PCSensor 1-WireRelay/I-O 装置 is needed, for a start.
Many things which you attach to LANs have all sorts of clever programming in them. The TEMPerLAN eschews this 複雑さ.
The 装置 watches for two hex bytes to arrive. If it sees "BB 82", it replies with a string like the に引き続いて....
BB 82 03 01 F4 01 6C 01 61 FF
The first two bytes are always BB 82
The 03 in the example tells me that there were three 気温 sensors 大(公)使館員d to the TEMPerLAN which was 存在 read.
The next six bytes were the 気温s seen. More on this in a moment.
The final byte of a valid reply will always be FF
Let me, once more, go 支援する to my (人命などを)奪う,主張する that this tutorial is of general importance.
ーするために "finish what we've begun", に向かって the end of this essay, I show you how to make use of the string returned by the TEMPerLAN. Those 詳細(に述べる)s are not of general significance. But 装置s that send SOMETHING in 確かな 誘発する/引き起こすing circumstances are ありふれた, and you might 井戸/弁護士席 make one or two of your own 工夫するing. And, whatever gets sent, 取引,協定ing with it is really a trivial 問題/発行する when you consider it beside the greater, and more 一般に useful 問題/発行するs of getting it from the server to the (弁護士の)依頼人.
So enjoy using a TEMPerLAN with this ソフトウェア, if you happen to have one... But those of you who don't have one don't need to stop reading yet! (The TEMPerLAN can 答える/応じる to other 命令(する)s, 同様に, but this essay concentrates on BB 82).
So... how is "01 F4 01 6C 01 61" three 気温s? (We'll come to how to send the BB 82 and fetch the reply in a moment)
First, 分裂(する) it up thus...
01 F4: first 気温 01 6C: second 気温 01 61: third 気温
(Which sensor 料金d "first", which "second", etc, is more or いっそう少なく 独断的な... but it will be constant for any given 始める,決める of sensors, by the way.)
"01 F4" is the raw "気温" as returned by the Dallas sensor, a DS18B20, if you want to 調査する the datasheet. It is a 16-bit, 調印するd, 2s complement number, 表明するing the 気温 in 16ths of a degree Celsius. Don't panic Mr. Mannering, I will be 取引,協定ing with the consequences of that for you. I only 報告(する)/憶測 the 詳細(に述べる) for my fellow obsessives, and to "show my workings", to help you if there are mistakes in this. (Surely not! But please 令状 and 知らせる me of anything you think is a mistake... That will help me look good if you are 権利, and help me tailor the text if you are wrong... you can save then next reader perplexity.) You are given the most 重要な byte first. Thus, if the sensor returned 0001, the 気温 it is seeing is 1/16th degree Celsius.
Changing the 気温s from sixteenths of degrees into hundredths of degrees isn't as hard as you might think. The 詳細(に述べる)s will be in the code, if you want them. The hard bits, for me anyway, were sending the BB 82 and reading the answer.
井戸/弁護士席... it was hard to pin 負かす/撃墜する what I had to do. And hard to find the 権利 tree in the forest which is the superb Internet 構成要素 控訴 from Francois Piette and the 抱擁する and generous ICS community. The ICS gives Delphi and C++ 建設業者 programmers the 構成要素s to build (弁護士の)依頼人/ server 使用/適用s, and the basic elements of many other 関係のある 使用/適用s.
It turned out that the ICS Client5 tutorial was about all I needed. What follows is an account of tweaking that to create "my" 使用/適用 for reading the TEMPerLAN.
The に引き続いて is a 大いに condensed 見解/翻訳/版 of my path to success, but I will try to 長,率いる you off from as many of the dead ends I 調査するd as I can remember.
To 正確に/まさに follow this, you need a TEMPerLAN, or SOMETHING that behaves as it does... something sitting on your LAN which 答える/応じるs when you send some bytes to it.
The first big 打開 for me was 存在 told about the marvelous, 解放する/自由な "SmartSniff", a packet sniffer. It shows you what's bouncing around you 網状組織. It is a little scary... you wouldn't believe all that's going on. It, like any powerful 道具, takes a little getting used to, a little mastering, but I will be helping you there.
You don't have to "任命する/導入する" it. (Unless you want to... you can get a 見解/翻訳/版 that gives you a nice "uninstall" button.) I used the 選択 I prefer: I downloaded a nice simple zip with a 選び出す/独身 nice simple .exe in it. I put the .exe someplace sensible. I put a shortcut to it someplace sensible. And I was done. (Mostly).
I say "mostly", because one of the 専門家s helping me said that because I was using Windows, I really ought also to 任命する/導入する WinPCap too... without it, SmartSniff was going to 行方不明になる some stuff. I think for my simple needs, it wasn't 現実に necessary, but if you are going to 始める,決める up a sniffer, you might was 井戸/弁護士席 始める,決める up a 包括的な one. While the SmartSniff "体制/機構" was a 微風, and the sort of Nice Simple ソフトウェア I like, WinPCap was a little more scary. As with anti-malware ソフトウェア, it does, of course, need to be 任命する/導入するd 深い in the bowels of your OS, and thus is never going to be "simple". And never going to be "安全な"... but I 手配中の,お尋ね者 what it 申し込む/申し出d, and so proceeded.
It isn't so much an 使用/適用 as a 始める,決める of drivers. When you have 任命する/導入するd it, your 支配(する)/統制する パネル盤 "追加する 除去する Programs" 名簿(に載せる)/表(にあげる)s 伸び(る)s an 入ること/参加(者) "WinPCap". And when you start SmartSniff... いつかs... it asks if you want to use WinPCap, or just "raw sockets". (That dialog is one that it is 平易な to skip over with glazed 注目する,もくろむs, because the question in it, to a newbie like me, anyway, seems abstruse, and it is 平易な to just click "okay", hoping for the best!) So! You need to 任命する/導入する WinPCap, and you have to tell SmartSniff to use it!
Yes, but what does SmartSniff do, I hear you wail....
Neat stuff!
But what it is doing, and what you think it is doing may not be the same thing!
解雇する/砲火/射撃 it up. Then use your browser to look at something, or even just refresh this page.
The SmartSniff 道具 has two パネル盤. At the 最高の,を越す is one filled with a line per (悪事,秘密などを)発見するd TCP/IP 関係.
Click on any one of those lines, and in the 底(に届く) パネル盤 you will get a 陳列する,発揮する of the traffic across that 関係 up to the time when you changed the line you have selected in the 最高の,を越す パネル盤. N.B.: You need to change away from "関係 A" to a different one and then 支援する to "A" to refresh what's shown in the 名簿(に載せる)/表(にあげる) of traffic.
You'll want to use the 再開する 逮捕(する) button (Keyboard shortcut: ctrl-R) from time to time, just to "少しのd the garden". Don't be alarmed by all that is going on. You may have a major ウイルス infestation, but a lot of activity in SmartSniff's windows doesn't やむを得ず mean that you do!
So! You've got SmartSniff running. You've refreshed something you have up in your browser. Click on a few of the lines in SmartSniff's 最高の,を越す パネル盤, ones for 議定書 TCP, remote 演説(する)/住所 something not starting 192, remote port 80, and 結局, you should つまずく upon something ばく然と like....
GET /js_ libs/js- lib_v2.js HTTP/1 .1..Host : www.overbyte.be..使用者- スパイ/執行官: Mozilla/5....
That's what I got just now when I refreshed a page from Overbyte.be, using Firefox.
You are seeing the "raw stuff" that your browser sent to the page you refreshed, and if you scroll 負かす/撃墜する the page, you will see the "raw stuff" your browser 陳列する,発揮するs so nicely for you. You have "tapped the line" between your browser and the internet.
Now a moment ago, I said "don't be 脅すd" when you start digging with SmartSniff. Not about all the traffic. Now I will show you something that SHOULD 脅す you.
Just before you do the next thing, do ctrl-r in your SmartSniff window, on the first PC.
Use the PC to, say, fetch some email.
Depending on how you do email, you may find 詳細(に述べる)s of your スピードを出す/記録につける on password, etc, in the SmartSniff 記録,記録的な/記録する of your "conversation" with your mail server. I wasn't able, this morning, to see such things from a conversation on a second PC on the LAN... but even if that's not possible, it wouldn't be hard to leave SmartSniff running on a PC in a 最小限に減らすd 明言する/公表する. And it is certainly possible to do SmartSniff type things with a blatantly malevolent program that is deliberately written to run "silently". And then there are keyloggers, of course. Yikes. Be careful out there, people.
Anyway... 支援する to いっそう少なく exciting things...
So... you've got SmartSniff 任命する/導入するd. Be sure to 熟知させる yourself will ALL the columns in the 最高の,を越す パネル盤... you'll have to use 水平の scrolling, column resizing, etc. You can save your preferred configuration with "とじ込み/提出する | Save Config..."
For each 関係, in the 底(に届く) パネル盤 you can see a history of communications. That history 含むs both 去っていく/社交的な messages and 後継の messages for the 関係 in question. You can watch the 人物/姿/数字s in the "data size" column to see which channels are active, and to see when something arrives.
Use "選択s | 陳列する,発揮する 方式" to get the results that are best for your needs. (Use "Hex 捨てる" if in 疑問... that will show you the data both ways... as (hex) numbers, and, at the 権利, characters when the datum has an 割り当てるd ASCII character, or a dot as a placeholder when it doesn't.
We are at last ready to start with the ICS デモ!
I'm assuming you have ICS 任命する/導入するd in your Delphi. For some work I 手配中の,お尋ね者 to do, I was told that I needed at least Delphi 5. Happily, I was able to lay my 手渡すs on a Delphi 7. I can't 解任する which ICS 見解/翻訳/版 I am on... probably an oldish one, to "fit" the Delphi 7. Thank you Overbyte.be for keeping the old 見解/翻訳/版s 利用できる!
I hate to lose the "初めの" 見解/翻訳/版s of anything I've downloaded, so I try to remember to always work with copies.
For today's 目的s, copies of all the OverByteIcsCliDemo and the OverByteIcsCliDemo1 とじ込み/提出するs are needed. On my system there were 6 in all, in the ICS/Delphi/Internet folder. Yes, those とじ込み/提出するs... even though I said it was the "Client5" デモ which was the 重要な to my success. (I 設立する the 指名するing of the elements of the ICS basic (弁護士の)依頼人 デモ 混乱させるing.)
早期に on in the 過程, I 改名するd the main form "TCP001f1", as I was calling the 事業/計画(する) TCP001.
When I ran the デモ as 供給(する)d, I got a window into which I had to fill port and server. And a little puzzle. To 確実にする that I was giving you the 権利 (警察などへの)密告,告訴(状), I started again, "from scratch", or so I thought. So how did the "new" instance of CliDemo know the IP 演説(する)/住所 and port I 手配中の,お尋ね者 to use? A little digging in the code turned up some "clever" stuff with an ini とじ込み/提出する. "Clever" stuff you may or may not welcome. I didn't look hard, but I couldn't find the ini とじ込み/提出する in any place that was obvious to me. Anyway... Once CliDemo is running (the window 肩書を与える says "(弁護士の)依頼人"), you need to tell it about...
You then type something... "xxx" will do... into the Data edit box, 攻撃する,衝突する ctrl-r on your SmartSniff 開会/開廷/会期, and click the "send" button of the (弁護士の)依頼人 デモ.
All that's needed with those settings, is that 装置 at 192.168.0.241 受託するs a 関係 on port 5200. The 装置 may or may not be able to do all sorts of clever things... but even the most 原始の 装置 will 受託する a 関係, and if it does, you'll be able to see in SmartSniff that your PC send "xxx" (or whatever) to the 装置 on 192.168.0.241 (or whatever) port 5200 (or whatever). If the 装置 is 欠陥のある or dead, or if you have one of the numbers wrong, or if your anti-malware ソフトウェア is 干渉するing, then after a short 延期する, in the (弁護士の)依頼人 window, you will see "Can't connect".
Remember also that SmartSniff does not update the 記録,記録的な/記録する of data passed until you de-select the 現在の 関係 and then re-select it.
Now, if sending "xxx" to your 装置 had any 深遠な 影響, I will be amazed. I suppose it might send 支援する an explicit "I don't know that 命令(する)" message.
With the TEMPerLAN, it will 答える/応じる if you send it BB 82. And so we come to another 詳細(に述べる) to be got 権利. Is that 5 characters of ASCII (counting the space)? Or just two bytes of data? If two bytes, does there need to be a space sent between them?
For TEMPerLAN, it turns out that it is two bytes of data, with no space between them. その上に, the sending program should not send a CR or LF に引き続いて the BB 82. (It does no "害(を与える)", 現実に... but it creates unnecessary traffic on the LAN, so why do it?)
Once you know this, and once you know how, it is 平易な to get (弁護士の)依頼人 to send the 権利 Stuff....
If you do that and click send, if you have a TEMPerLAN at 192.168.0.241, then SmartSniff should not only show the BB 82 (and the hyphen) going to the TEMPerLAN, it should also see something come 支援する from the TEMPerLAN! The bytes sent by your PC are shown in blue, the bytes received are shown in magenta.
The 加える 調印する on the end is a bit of a 一時的な kludge along the way to a final answer with no corresponding kludge. The (弁護士の)依頼人 デモ, at least the 見解/翻訳/版 I was using, has (I think) a fencepost error... If you ask (弁護士の)依頼人 to send "$BB$82" it (正確に) 変えるs the three ASCII characters "$"+"B"+"B" to a 選び出す/独身 byte, hex BB. Because of what is, I think, a 欠陥, the program does not, as it should(?) 変える the final "$82". However... by 追加するing the 加える 調印する, we can "直す/買収する,八百長をする this". The 加える 調印する means that the "$82" is NOT the final part of the string 明示するing what data to send, and "変える $xx to a byte" 機械装置 作品, and $82 does get 変えるd to a 選び出す/独身 byte and sent as such. Then the byte that stands for a 加える 調印する in the ASCII code gets sent. Fortunately, the TEMPerLAN just ignores this extra byte.
(The 見解/翻訳/版 of CliDemo I was working from had the に引き続いて in it...
CliDemoVersion = 107; CopyRight : String = 'CliDemo (c) 1997-2010 F. Piette V1.07 ';
Having seen "BB 82", the TEMPerLAN sends 支援する to whoever sent the "BB 82" (our PC, in this 事例/患者) the string of bytes which 含む/封じ込めるs number of sensors 存在 read, and the 気温s seen by each. Hurrah!!!
(If you are not seeing this, are you remembering that SmartSniff doesn't always 陳列する,発揮する the 最新の data? That you have to move away from, and then 支援する to, the 関係 that 利益/興味s you, if you want to see the 最新の data?)
We don't need, for our 目的s, to be able to change what we send to TEMPerLAN. But we do need to "逮捕(する)" what is sent 支援する. So....
We're going to 修正する SendData 手続き. Happily, the 初めの author made it nice and concise. We're going to make it even more concise, because we don't have to "過程" the "stuff" coming to SendData from the "Data" (to send) edit box.
After our tweaks, SendData is just...
手続き TTCP01f1.SendData;
var
Buf : String;
begin
try
Buf := #$BB#$82;
CliSocket.SendStr(Buf);
except
on E:Exception do 陳列する,発揮する(E.ClassName + ': ' + E.Message);
end;
ActiveControl := SendEdit;
SendEdit.SelectAll;
end;
Once that is working... use SmartSniff to see that it is working... you can 削除する lots of 構成要素s from the (弁護士の)依頼人 form. 削除する...
When you try to run the program after 削除するing those 構成要素s, you'll have to make a few changes. You don't have to 追跡(する) these out... just try to run the program, and 直す/買収する,八百長をする things as the compiler 報告(する)/憶測s them...
ActiveControl := SendEdit;
... becomes, in two places,...
ActiveControl := SendButton;
SendEdit.SelectAll;
... and...
IniFile.WriteString('Data', '命令(する)', SendEdit.Text);
... and...
SendEdit.Text := IniFile.ReadString('Data',
'命令(する)', 'LASTNAME CAESAR');
... are just 除去するd.
At the moment, we only see the answer from the TEMPerLAN if we use SmartSniff. 現実に, we can often see a hint of an answer by clicking "Disconnect" after clicking "Send"... but we do not get a 満足な result even then at this 行う/開催する/段階.
The result is unsatisfactory because the TEMPerLAN is 答える/応じるing with bytes from the whole 範囲 of 0-255, and the デモ was 始める,決める up 推定する/予想するing to 扱う just printable ASCII. In the code for ProcessCommand, you will see 陳列する,発揮する(Cmd);
Change that to DisplayHex(Cmd); and create DisplayHex, as follows. Remember to 追加する the 今後 宣言 of DisplayHex up at the 最高の,を越す of the code, too. (Just below the 今後 宣言 of 陳列する,発揮する is the 平易な and 論理(学)の place to do that.) Our "DisplayHex" won't be as elegant as the 初めの "陳列する,発揮する", because it won't.... until you 修正する the code 現在のd here for yourself... 限界 the number of lines in DisplayMemo. That's 平易な enough to do, erasing the oldest line when the, say, 10th (and その後の) new lines are 追加するd to the 覚え書き. Nor does it を取り引きする さまざまな clever things that were too high for me.... but it DOES 現在の what was returned by the TEMPerLAN in a readable form... but, so far, only if you click "Disconnect" after clicking "Send". We'll 直す/買収する,八百長をする that problem next.
Keep the old "陳列する,発揮する" 手続き, as it is used for putting さまざまな messages into DisplayMemo.
Now, at least if click "Send" and then "Disconnect", we can usually see at least some of the data which is coming 支援する from the TEMPerLAN. But we should not need to connect and disconnect 繰り返して. And we don't. To understand what is going on, we'll take a little detour to look at how the (弁護士の)依頼人 デモ 作品.
The (弁護士の)依頼人 デモ is built using just one ICS 構成要素, the TWSocket 構成要素.
There's (警察などへの)密告,告訴(状) about type TWSocket 構成要素s in the OverByte ICS Wiki.
The に引き続いて is a story of TCP communications between 装置s... a 広範囲にわたって used answer. There is at least one 代案/選択肢: UDP. TCP is the 創立/基礎 upon which many things you will be aware of is built... many email systems, the World Wide Web, for starters. UDP can be a story for another day. (If you want a beginner's discussion of TCP vs UDP, you are advised to read the good TCP / UDP Primer at Overbyte.be, the home of the Internet 構成要素 控訴.)
The "conversation" begins with the 開始 of a channel, a "関係". The 過程 is 類似の to the 設立 of a とじ込み/提出する 扱う, if you are familiar with reading and 令状ing datafiles. "Creating a socket" may be 正確に/まさに the same thing... or it is at least の近くに in my "one 注目する,もくろむd king" mind. This 要求するs 資源s, and so, 結局, the channel should be の近くにd, to return those 資源s to the general pool that Windows draws upon. One channel creates one line in the upper パネル盤 of the SmartSniff 陳列する,発揮する.
In the (弁護士の)依頼人 デモ (or the derivative we have been creating), have a look at the SendButtonClick 手続き. If you 港/避難所't clicked SendButton since the 使用/適用 was last 再開するd (or if for some 推論する/理由 your 関係 has been lost), there is code in SendButton to start making the 関係. We'll come 支援する to that in a moment. If we are already connected to the 装置 we want to talk to 経由で a TCP channel, then SendButton just calls the SendData 手続き... the 手続き that takes care of sending something off, which we will also come 支援する to. Later.
The CliSocket 反対する in the (弁護士の)依頼人 デモ is an instance of the TWSocket 構成要素, from the ICS. There's a good 言及/関連 to the TWSocket 構成要素 online, but I will cover here what you need to know for our TEMPerLAN (弁護士の)依頼人.
One 所有物/資産/財産 of any TWSocket 構成要素 is it's 明言する/公表する 所有物/資産/財産. And one of the constants built into ICS is wsConnected. In our 使用/適用, we only have to look to see if CliSocket.明言する/公表する=wsConnected to know if there is an open channel between our computer and the remote 装置. So simple when you're taken to this point by 手渡す, so hard when you are new, and have too many things to think about at once!
So... if we are connected, we just send our data. But how did we get connected? That is a more subtle story than you might have thought!
Still in SendButton, in the "else", we see several 所有物/資産/財産s of CliSocket 存在 始める,決める, and then a call of CliSocket's "Connect" method... but no call of SendData! Doesn't the data get sent the first time we click the SendData button? It does get sent... just not yet. Here's the thing....
When we call CliSocket.Connect, the system goes off and tries to make the 関係 we've asked for. It may not 後継する! Even if it does, it will take time. 持つ/拘留する those thoughts.
Now 解任する that Windows and Linux are multitasking, event driven 環境s.
While our little 使用/適用 is running, other things are going on 同様に. Even within our 使用/適用, there may be things (like a Timer 構成要素 counting 負かす/撃墜する) going on that are not "obvious". But those other things can "raise events"... i.e. they can, if we've written our 使用/適用 to 答える/応じる to those events, "hi-jack" our 使用/適用, and 原因(となる) it to run an event handler.
In the (弁護士の)依頼人 デモ, there is a handler for an OnSessionConnected event from CliSocket. (The 反対する 視察官, "Events" tab, is one way to see that this is so.)
When we called the Connect method of CliSocket, "behind the scenes", the CliSocket 反対する started trying to connect によれば the settings we'd made in the 反対する's 所有物/資産/財産s. When the 試みる/企てる finished, successful or not, the OnSessionConnected event arose, and our program went off to the CliSocketSessionConnected 手続き, and did what we have there... which was either to 陳列する,発揮する a message 説, "Sorry, failed to connect", or to... shazam!... call "SendData". You should have been impressed when you 設立する that "SendData". In 事例/患者 you weren't, let me recap...
When you click the Send Data button, IF you are "connected" a 手続き called SendData is called. ("SendData" is not the handler for the Send Data button.)
If you are not connected, you start the connecting 過程, but do not... within the handler for the Send Data button... call the SendData 手続き. But you do start something which will 結局 原因(となる) an event (OnSessionConnected) and, within that, if appropriate, the SendData 手続き will (at last... but earlier was too soon) be 遂行する/発効させるd.
The SessionConnected event might more descriptively be called "AttemptToMakeAConnectionHasEitherSucceededOrFailed"... but I think we can 許す the authors of ICS for giving it an 楽観的な 指名する in the 追跡 of conciseness?
権利! Moving on! If we made a reasonable request, we are by now connected. Our computer and some remote 装置 (the TEMPerLAN, in this 事例/患者 熟考する/考慮する) are connected. You can imagine it as if telephone wires have been strung between them, although of course the physical wires (or WiFi link) were 現在の all the time.
Once the 関係 is there, it is time for the innards of the SendData 手続き....
The heart of that is...
CliSocket.SendStr(Buf);
We 用意が出来ている the way for that by putting what we 手配中の,お尋ね者 sent into Buf before calling SendStr. As you might guess from the 指名するs, "Buf" is a 衝撃を和らげるもの, 持つ/拘留するing a string of bytes, and SendStr tries to send it off to whatever the socket is connected to. (And then again, you might have guessed any one of a number of other things, which is why I wrote out what I did!)
公式文書,認める that the bytes in a string don't have to be bytes from the 範囲 割り当てるd to printable ASCII. If you say Buf:=#$41#$42#$43 you are working harder than you need to. You could just have said Buf:='ABC'. But the TEMPerLAN, bless it, 手配中の,お尋ね者 some 非,不,無-printable bytes sent to it to make it "do its trick" (send 支援する the 気温 readings). Hence the Buf := #$BB#$82;
And that's pretty 井戸/弁護士席 it, for SendData... apart from 取引,協定ing with errors which may be 報告(する)/憶測d 経由で an event 誘発する/引き起こすd by the call of SendStr.
So how do we get our answer???
There are 多重の ways to 肌 a cat, and 多重の ways to communicate over LANs and WANs.... this tutorial covers one way, the LineMode way. That, for TEMPerLAN, is the wrong way, I realized, a long way into the 事業/計画(する)... sigh. There's a discussion of why it is the wrong way later. For now, just pretend (it isn't true) that an $FF will never occur within what the TEMPerLAN returns to the (弁護士の)依頼人, except as the End Of Line (End of 記録,記録的な/記録する) 指示する人(物). Even though we are using LineMode with a TEMPerLAN, our 使用/適用 will USUALLY work 罰金. It won't work if the sensors are 冷淡な (below 氷点の). If the sensor is 徐々に warming or 冷静な/正味のing, and, just by chance, sending every possible reading along its 範囲, you will also get an error once in every 256 readings. So if you get errors from time to time, just しっかり掴む the sensor with a warm 手渡す, change its 気温. You have a 255/256 chance of changing it to something that will be read 適切に, even by our 欠陥d program.
I've re-written the code, using a different approach, one that doesn't care if a "逸脱する" $FF arises. When I get time, I will 含む the 収集するd .exe in this tutorial's .zip とじ込み/提出する. It will be called TCP002.
Let's get 支援する to work!
At the point a while ago, in the code for what settings would be sent to CliSocket, our instance of the TWSocket 反対する, we said we 手配中の,お尋ね者 LineMode=true for the 関係, with the LineEnd character 始める,決める as 255, aka $FF.
(The line end character can, by the way, be any byte or short string of bytes. A two byte string consisting of the codes for a line 料金d and a carriage return is often used as the LineEnd "character". They are 代表するd many ways, e.g. "CR/LF" (in essays), or #13#10, or #$0D#$0A.)
With the socket 始める,決める up that way, here's what happens when our 関係 is up and running:
A 衝撃を和らげるもの in the bowels of ICS and the operating system 蓄積するs any bytes arriving over the 関係 until the LineEnd byte (or string of bytes) is seen.
At that point, an OnDataAvailable event arises, the デモ has 大(公)使館員d the handler called CliSocketDataAvailable to that. 公式文書,認める that, in these 条件, data isn't "利用できる" until a whole line of data has become 利用できる. "A whole line" is defined by the arrival of the LineEnd byte or byte-string.
Once a line of data is "利用できる", as you can see in the CliSocketDataAvailable 手続き, you can fetch that line from the bowels of ICS with the Retrieve method. There 's also a RetrieveStr method, which I though looked いっそう少なく obscure... no need to use "@", no need to append the Null (#0)... but the people who wrote the (弁護士の)依頼人 デモ know more about these things than I do, so I left things as they had them.
So much for most of what you need to know about working with TPC, "the 関係", sockets, etc. There is a little housekeeping... when you are done, you should の近くに the 関係 (see DisconnectButtonClick). The author of the デモ seems content to let the general 準備/条項s of 使用/適用 shut-負かす/撃墜する take care of any necessary の近くにing of the 関係. In other words, if you choose to の近くに the 使用/適用 without first disconnecting the TCP channel, then there will be no problems for your computer and the other things running in it.
You should have an event handler to tell you if the 関係 is broken... it may be の近くにd from the other end at some point, for instance. In the デモ, this is 扱うd by CliSocketSessionClosed, which is the handler for CliSocket's OnSessionClosed event.
I have ducked explaining at least one area which may be important. Here's one that I know about.
There are some 所有物/資産/財産s of the socket with "KeepAlive" in their 指名するs. I believe this is something to do with periodic checks that the channel is still there, but I don't know. For now, and for the 目的s of reading 気温s from the TEMPerLAN, the default values for these 所有物/資産/財産s seem 十分な.
Enough about keeping alive.
You will also find 構成要素 in the デモ, e.g. in FormClose about an ini とじ込み/提出する. The ini とじ込み/提出する is only there so that you don't have to keep re-entering the port and server you want to connect to. Oh, and it also 供給するs the way the 使用/適用 remembers any re-sizing of the window you may have done. Excellent things, ini とじ込み/提出するs, but not something you need to use the ICS. (An ini とじ込み/提出する 機能(する)/行事 is 供給するd in ICS... GetIcsIniFileName... which returns a string. That string 供給するs a path and 指名する for a とじ込み/提出する, and the デモ uses that とじ込み/提出する for the 使用/適用's ini とじ込み/提出する. If you changed...
IniFileName:= GetIcsIniFileName;
... to...
IniFileName:='C:\TCP001ini.txt';
... then you would make the ini とじ込み/提出する for this 使用/適用 be C:\TCP001ini.txt, which is a good 指名する, but a very 天然のまま "answer" to 決定するing where the ini とじ込み/提出する will be 蓄える/店d. I think... no 約束s, but there is a way... that the に引き続いて would put the ini とじ込み/提出する in the .exe's folder...
IniFileName:='TCP001ini.txt';
井戸/弁護士席... sort of. The hard TCP stuff is out of the way, anyway. At least I hope I've explained all of that. Re-read what is above, if you are still perplexed on a TCP 問題/発行する.
What's left? What 港/避難所't we dealt with??
Remember that, for argument's sake, you have a TEMPerLAN, and you want a program to 監視する what its sensors are seeing.
By the way... you can put 192.168.0.241 into the "server" edit box to look at a TEMPerLAN at that IP 演説(する)/住所 on your LAN... or you can put mon7NC.dyndns.org into the "server" edit box (still 5200 in the "port" edit box) if you have connected the TEMPerLAN to the internet 経由で the URL given. No changes are needed to TCP001... but the setting up of the other elements, while not ロケット/急騰する science, isn't trivial. See my 公式文書,認めるs on FarWatch or the ArduServer if you are 利益/興味d.
By the way... one little 欠陥 in the 使用者 friendliness of the ソフトウェア... If, after connecting to something, you change what is in either of the edit boxes and click "Send" again... No notice is taken of what you put in the edit boxes. The BB 82 will still be sent where it was sent 以前.
You might think that 簡単に 追加するing a
DisconnectButtonClick(nil);
... to a ServerEditChange 決まりきった仕事 would be the answer, but that gets a bit 絡まるd... you can't for instance, call DisconnectButtonClick while the system is in the 中央 of an 試みる/企てる to connect.
The 直す/買収する,八百長をする probably せねばならない be done, but I 港/避難所't the energy for it now! (Maybe just 無能にする the two edit boxes while a 関係 存在するs, or is 存在 試みる/企てるd? This would 軍隊 使用者s to click "Disconnect" (you would 追加する "re-enable edit boxes" to that) before the 使用者 could try to change the port or server?
ANYWAY... what was the bit that hasn't been dealt with yet??
...
...
... last chance to think of it for yourself!...
v v v
Did you say "陳列する,発揮する the data as 気温s, instead of as computer friendly strings of hex."?
If so: Gold 星/主役にする!
At the moment, when the data comes 支援する, thanks to our "DisplayHex" 手続き, it looks something like...
BB 82 03 01 EE 01 80 01 71
The string starts with BB and 82. The next number is the number of 気温 sensors connected to the TEMPerLAN. Then, 2 bytes per reading, we have the readings. Remember that what was 現実に sent was the above, 加える a FF at the end, to 示す the end. The FF is stripped off before the string goes to DisplayHex.
Before we can proceed, a 汚い little fact has to be 直面するd.
Suppose the reading from the first sensor is, say 01 FF?
That datum would fool our TEMPerLAN reading ソフトウェア. The DataAvailable 決まりきった仕事s are going to think that the FF in the 気温 reading 示すs the end of the whole message. Not only will this leave us with a too-short message now, but in a moment, we 井戸/弁護士席 get the second half... we'll be sent...
01 80 01 71
... as if THAT were a proper 記録,記録的な/記録する from the TEMPerLAN, and new problems would arise!
Happily, there is a 解答... but I'm not going to explain it in 詳細(に述べる) here. We will proceed with our discussion of how to do (弁護士の)依頼人/ server stuff using LineMode=true on the (欠陥d) understanding that the TEMPerLAN won't send $FF, except as the end of line marker. (It will send $FFs once in a while, but at above 氷点の 気温s, rarely.)
I'm going to ramble for a little bit. You can skip 負かす/撃墜する to the next 長,率いるing, if you want to.
The whole "what can we do about the $FFs" question took me 負かす/撃墜する several paths which illustrate nicely the messes you can get into if your feet (or, in the 事例/患者 of programming, I suppose we should say fingers) are moving faster that your brain.
When you try to fudge things, it usually ends in 涙/ほころびs. いつかs we attack the wrong problem. In this program, in spite of all I had 投資するd in the LineMode=true "answer", using LineMode was the problem. Changing that was what I needed to do. But look at the ways I tried to squirm out of doing things the 権利 way....
First, I said to myself, maybe the Nice People at PCSensor built the TEMPerLAN with a little fudge in it. It would be 平易な enough to 直す/買収する,八百長をする things so that the TEMPerLAN would 報告(する)/憶測, for instance, 01FE when the reading was 現実に 01FF. Would a sixteenth of a degree Celsius ever 事柄?
Always be 警報 for any such "would it 事柄" thoughts. They almost always arise when you are thinking of doing something foolish.
If getting 01FF into the data packet were our only problem, then the little cheat might have saved the day. But I don't think that the PCSensor engineers did that. For one thing, I did, about 1 time in 256, get an error which could have been 原因(となる)d by a datum 含む/封じ込めるing an $FF. But there's a "取引,協定 breaker"....
Changing 01FF to 01FE is do-able, and not so very terrible.
However... to send 気温s which are わずかに below 無, the TEMPerLan needs...
Unless you're willing to have the first 256/16ths of a degree below 無 all 報告(する)/憶測 as -257/16ths of a degree below 無, the "send any FFs as FE" answer doesn't work. Sigh. But the fact that we were trying to fudge things with a little "井戸/弁護士席 this wouldn't 事柄 much" answer should have been a red 旗.
So. That won't work. Still trying to save the wrong thing, still trying to save doing it with a LineMode=true answer, I then turned to the に引き続いて dog's dinner...
I could, I told myself, 令状 things to take the "data FF" into consideration... if I got an FF "too soon" (and of course, just 決定するing that would be one 頭痛) I could "save" what had arrived so far, and fetch another "line". Then I'd 追加する the two together, and use that. Yes, 井戸/弁護士席, maybe you could. (You'd have to 供給する for the fact that there might be more than one "data FF" before the EndOfLine FF, by the way.) But going 支援する to the 初期の 欠陥のある 前提: "Use LineMode=true", and changing that 証明するd to be the 権利 answer.
But it would mean a very 広範囲にわたる re-令状 of this tutorial, and a re-令状 of the code. And there are many 事例/患者s where using LineMode=true is 罰金. So I left the tutorial alone!
You can use the nice, 平易な, LineMode=true approach whenever you can identify a byte or byte-string which will not arise within the line you are trying to send. If TEMPerLAN were re-programmed to send the 気温s in ASCII, a simple thing to do, a TEMPerLAN (弁護士の)依頼人 program could use LineMode=true.
TCP002.exe (to be 含むd in the TCP001.zip soon, if it isn't there already) was written with LineMode=誤った. It will read and 報告(する)/憶測 every 気温 that TEMPerLAN can send.
End of Ramble.
I could just give you "the answer", but this is meant to be a tutorial, so I will take you through how I got to the answer.
At this point, our program has just one place where it calls "DisplayHex".
We're going to leave the DisplayHex 手続き in place, just in 事例/患者 we need to go 支援する to looking at the raw data from a TEMPerLAN (or 類似の 装置) at some point.
But 取って代わる the call "DisplayHex(Cmd)" with "DisplayTtures(Cmd)", and 始める,決める up the に引き続いて DisplayTtures 爆撃する...
手続き TTCP01f1.DisplayTtures(Msg : String);
var
sTmp: string;
begin
sTmp:='There were '+inttostr(length(Msg))+' bytes in the 記録,記録的な/記録する';
DisplayMemo.Lines.追加する(sTmp);
end;
What follows will not be the most elegant way to 達成する our end... but I hope it will be exceedingly transparent and 強健な.
At the start of DisplayTtures, we are going to look at the string that was passed to it, and check it for さまざまな possible 欠陥s. While we're at it, we're going to 抽出する a piece of (警察などへの)密告,告訴(状), if the string is valid. A CheckRecord 手続き will be used; it will pass things 支援する to the place where it is called by using var parameters. To get that started, we will look to see if the first byte of the string is hex BB. Here's all of DisplayTtures again, in its growing form. Try that, and then just change the BB to BA, so you can see what happens if the 記録,記録的な/記録する doesn't 会合,会う 期待s.
手続き TTCP01f1.DisplayTtures(Msg : String);
var bErr,bCountTtures:byte;
{subroutines of DisplayTTurees...}
手続き CheckRecord(Msg:string; var bErrL,bCountTturesL:byte);
//The variables do not need the "L" suffix for things to work, but
// having them may save 混乱 for readers not yet fluent in 事柄s
// of 範囲.
begin
bErrL:=0;// if this is still 無 at the end of the 手続き
//call, then no errors were 設立する.
bCountTturesL:=255;//a rogue value, but to give this variable
//SOME, defined, value, in 事例/患者 it doesn't get one さもなければ
if length(Msg)=0 then bErrL:=1;
if (bErrL=0=0) and (Msg[1]<>#$BB) then bErrL:=2;
end;//of CheckRecord
{end of subroutines of DisplayTTurees...}
var
sTmp: string;
begin
CheckRecord(Msg,bErr,bCountTtures);
sTmp:='There were '+inttostr(length(Msg))+' bytes in the 記録,記録的な/記録する. ';
if bErr=0 then sTmp:=sTmp+'No errors seen in 記録,記録的な/記録する.'// no ; here
else sTmp:=sTmp+'One or more errors seen in 記録,記録的な/記録する.';
DisplayMemo.Lines.追加する(sTmp);
end;
That pretty 井戸/弁護士席 illustrates most of what we need to know. We will do more of the same. 結局, if it turns out that the string we are 取引,協定ing has 生き残るd all out data validation 実験(する)s, the data will be 変えるd to numbers that a 非,不,無-geek can comprehend. But these things are mere 詳細(に述べる)s. I will not, in this essay, go beyond a simple 使用/適用 to periodically fetch data from the TEMPerLAN and 陳列する,発揮する it as text. Putting the numbers in a graph would be a 重要な 拡張, as far as the 使用/適用's 使用者 friendliness is 関心d... but not an 利益/興味ing programming challenge different in any way from plotting values from a 地元の sensor. (So 捜し出す out a different tutorial if it is plotting data you want to know about!)
So far we've checked that the string we received has at least five bytes in it, in 新規加入 to the $FF which was 解釈する/通訳するd as signaling the end of a line, aka a 記録,記録的な/記録する. There must be at least this many bytes in the 記録,記録的な/記録する, even if the TEMPerLAN is connected to only one sensor.
(The 終点 $FF was 利用できる to our program, but code from the デモ, in ProcessCommand, 除去するd it, and I didn't notice that was where the $FF was "disappearing" until after this essay was "done".)
We have checked that the first byte in the string is a $BB, which is what TEMPerLAN is supposed always to start the 記録,記録的な/記録する with.
Next we will....
Check that the second byte is an $82, also constant in reply to the 命令(する) we're 供給するing a (弁護士の)依頼人 for.
If things 港/避難所't fallen over yet, we will 選ぶ up the third byte, and 蓄える/店 that as the number of sensors connected to the TEMPerLAN, which is what the third byte is supposed to tell us.
We'll need that number for the next 実験(する), and if the next 実験(する) fails, it will tell us that either the TEMPerLAN isn't sending what it should for readings, or that the "number of sensors" datum was incorrect.
If we're still in 商売/仕事, which we should be, "all" that 's left now is to 収穫 the readings data, 変える them to human friendly form, and 陳列する,発揮する the readings!
Our reward for all that careful planning is that 器具/実施するing it is やめる 平易な.
Two big bits of that were dealt without anything fancier than....
if (bErrL=0) and (Msg[1]<>#$BB) then bErrL:=2;
if (bErrL=0) and (Msg[2]<>#$82) then bErrL:=3;
Fetching the number of sensors 報告(する)/憶測d, and whether the 全体にわたる 記録,記録的な/記録する is the 権利 length for that wasn't a lot harder. All of these things were done in the CheckRecord subroutine. If it returns 0 in bErrL, then all was 井戸/弁護士席. Any other number 示すs an error, and which error can be 決定するd by looking at the code. If bErrL is 無, then the number in bCountL is how many 気温 readings were returned by the TEMPerLAN. (If bErrL is not 無, the number in bCountL may 井戸/弁護士席 be meaningless.)
In a moment, I'll give you the code which does what I've 述べるd so far. 公式文書,認める that we have still funked 現実に collecting, 変えるing and 現在のing the 気温 readings. 公式文書,認める a little "extra" I've slipped in: The data lines now have a "B:" (for "bad") pre-pended to 生産(高) strings 報告(する)/憶測ing some problem, and "G:" pre-pended to 生産(高) strings with no problem. The 生産(高) strings will 結局 持つ/拘留する the readings. We may also want to 供給する the 使用者 with a hex 捨てる of the raw 記録,記録的な/記録する from the TEMPerLAN. Any such debugging (警察などへの)密告,告訴(状) will be given a "D:" prefix.
手続き TTCP01f1.DisplayTtures(Msg : String);
var bErr,bCountTtures:byte;
sTmp: string;
{subroutines of DisplayTTurees...}
手続き CheckRecord(Msg:string; var bErrL,bCountTturesL:byte);
//The variables do not need the "L" suffix for things to work, but
// having them may save 混乱 for readers not yet fluent in 事柄s
// of 範囲.
begin
bErrL:=0;// if this is still 無 at the end of the 手続き
//call, then no errors were 設立する.
bCountTturesL:=255;//a rogue value, but to give this variable
//SOME, defined, value, in 事例/患者 it doesn't get one さもなければ
if length(Msg)<5 then bErrL:=1;
if (bErrL=0) and (Msg[1]<>#$BB) then bErrL:=2;//Check 訂正する 記録,記録的な/記録する 1st byte
if (bErrL=0) and (Msg[2]<>#$82) then bErrL:=3;//Check 訂正する 記録,記録的な/記録する 2nd byte
if (bErrL=0) then begin // start of 封鎖する 遂行する/発効させるd to
//fetch number of readings, see if total 記録,記録的な/記録する size 権利 for that
//number of readings....
bCountTturesL:=ord(Msg[3]);
if length(Msg)<>3+2*bCountTturesL then bErrL:=4;
end;//封鎖する 遂行する/発効させるd to fetch number of readings, check 記録,記録的な/記録する length
//if bErrL still 0, then problems not 設立する. USING the readings in the
// 記録,記録的な/記録する used OUTSIDE of this subroutine.
end;//of CheckRecord
機能(する)/行事 CreateAnswerString(MsgL:string; bReadings:byte):string;
begin
result:='G:記録,記録的な/記録する had '+inttostr(bReadings)+' readings.';
end;// of CreateAnswerString
{end of subroutines of DisplayTTurees...}
begin //main 封鎖する of DisplayTtures
CheckRecord(Msg,bErr,bCountTtures);//if bErr=0 after this, all was 井戸/弁護士席.
sTmp:='There were '+inttostr(length(Msg))+' bytes in the 記録,記録的な/記録する. ';
if bErr=0 then sTmp:=CreateAnswerString(Msg,bCountTtures)// no ; here
else sTmp:='B:One or more errors seen in 記録,記録的な/記録する. '+
'One was error ID '+inttostr(bErr);
DisplayMemo.Lines.追加する(sTmp);
end; // of subroutine DisplayTtures
Now we will create the code needed in "CreateAnswerStringForGoodRecord". It may look コンビナート/複合体, but remember... it is just changing a number of 16 bit (2's complement) numbers 表明するing 気温s in sixteenths of degrees Celsius into ASCII strings, of a 直す/買収する,八百長をするd 判型, 表明するing the 気温s in decimal numbers of Celsius degrees.
I really don't think you need to 熟考する/考慮する this 特に closely. The important parts of this tutorial are どこかよそで!
To 避ける 確かな 問題/発行するs, only integer data types were used in the programming. I would like to thank whoever created the DS18B20 reading 決まりきった仕事s 設立する in many Arduino tutorials, the ones not using an Dallas library, for showing me the "divide by 6.25" trick... I first saw it in some code from NuElectronics.com, where I bought a nice datalogging 保護物,者.
The 気温 is first 変えるd into hundredths of degree Celsius, and then the lower two digits of that are put in one variable (smiTtureD ("decimal" part)), and the 残り/休憩(する) of the number, the number of whole degrees Celsius is put in another variable (smiTtureU ("upper" part)), and then with those the strings are built.
Please don't abbreviate "気温" as "temp", which is too 平易な to 解釈する/通訳する as "一時的な". Use "tture"?
Anyway... be that as it may, here's the code!
機能(する)/行事 CreateAnswerStringForGoodRecord(MsgL:string; bReadings:byte):string;
var sTmp, sTmp2, sTmp3:string;
smiTtureU,smiTtureD:smallint;//"U" 部隊s part, "D" decimal part,
//but smiTtureU used in 早期に 行う/開催する/段階s to 持つ/拘留する whole tture
//while it is still 表明するd in 1/16ths of a Celsius degree,
//and smiTtureD used as a "Tmp" 簡潔に...
bLoop:byte;
//If TEMPerLAN had 2 sensors, reading -2.3 and 15.2, then the string
//created should be...
//G:02 -002.30 +015.20
//The answer should always consist of...
//'G:', then
//Number of 気温s, with 主要な 0 if <10, then
//The readings, each of them starting + or -, and each using
// three digits before the decimal point, two after it.
// (無 to be 報告(する)/憶測d as +000.00)
//This rigid, 直す/買収する,八百長をするd length 判型, is to help programs as
// yet unwritten which will use the data brought this
// far, so far.
//This subroutine looks fearsome, but it is just a bunch
// of stuff to 解釈する/通訳する the 気温s as 報告(する)/憶測d
// by the Dallas 18B20 半導体素子s, and to 表明する them in
// the 判型 I decided upon.
//The readings arrive as 16 bit, 2's complement numbers.
// $0001,$0002,$0003.. mean 1,2,3!
// $FFFF is -1.... i.e. that the 気温 is 1/16th
// of a degree Celsius below 無.
begin
sTmp:=inttostr(bReadings);
if bReadings<10 then sTmp:='0'+sTmp;
sTmp:='G:'+sTmp;
//Use the に引き続いて to 挿入する 実験(する) data, to see if さまざまな
// data give the 訂正する 要求するd result.
//One pair per reading, MSB first. Don't use more
// elements of MsgL that is appropriate for the number
// of sensors on your LAN. E.g. if you only have two
// sensors, rem out the MsgL[8] and MsgL[9] lines.
{ MsgL[4]:=#$0;
MsgL[5]:=#$1;
MsgL[6]:=#$0;
MsgL[7]:=#$0;
MsgL[8]:=#$FF;
MsgL[9]:=#$FF;
}
//Delphi and inttostr 変える smallint type (調印するd 16 bit)
// data やめる nicely... but without the 主要な and 追跡するing
// spaced I 手配中の,お尋ね者.
//More use of real numbers was another 可能性, but one
// I 手配中の,お尋ね者 to 避ける.
for bLoop:=1 to bReadings do begin
sTmp2:=' ';//start building a number, pre-pended by a space
smiTtureU:=256*ord(MsgL[2+bLoop*2])+ord(MsgL[3+bLoop*2]);
if smiTtureU<0 then begin
sTmp2:=' -';//start building a number, pre-pended by a space
smiTtureU:=smiTtureU*-1;
end //no ; here
else begin
sTmp2:=' +';//start building a number, pre-pended by a space
end;//else
//Multiply number of 16ths by 6.25 to make it number of 100ths
smiTtureD:=smiTtureU div 4;
smiTtureU:=smiTtureU*6+smiTtureD;
//smiTtureU now 持つ/拘留するs tture in 100ths of deg C
//now work out decimal part of the tture...
smiTtureD:=smiTtureU mod 100;
//変える smiTtureU (100ths) to degrees, shorn of fraction part
smiTtureU:=smiTtureU div 100;
//変える each to a string, with 主要な 無s as needed...
// 追加するing bits to the final answer 衝撃を和らげるもの as we go...
sTmp3:=inttostr(smiTtureU);
while length(sTmp3)<3 do sTmp3:='0'+sTmp3;
sTmp2:=sTmp2+sTmp3+'.';
sTmp3:=inttostr(smiTtureD);
while length(sTmp3)<2 do sTmp3:='0'+sTmp3;
sTmp2:=sTmp2+sTmp3;
sTmp:=sTmp+sTmp2;
end;//... end of 宙返り飛行 to 追加する bReadings ttures to 生産(高) string.
result:=sTmp;
end;// of CreateAnswerString
It gets rather boring hitting the "Send" button over and over again. Because of the way we put the program together, it is 平易な to get it to read the TEMPerLAN 繰り返して. All we need to do is 追加する a Timer 構成要素. I called it tiReadAgain, to 反映する the point of having it.
In the FormCreate 手続き, I 始める,決める the timer's enable 所有物/資産/財産 to 誤った, and the interval to a default 2000, which makes the read interval 2 seconds. When it times out, the SendButtonClick 手続き is called.
I created a button which enables the timer. It also has its enabled 所有物/資産/財産 始める,決める to 誤った in FormCreate. The button is enabled when the 関係 to the TEMPerLAN has been made, and 無能にするd again (and the timer 無能にするd) when the 関係 is broken.
Button buReadAgain (labeled Enable 自動車-read), enables the timer. Duh?
I won't 約束 that every 詳細(に述べる) of that is 権利 at this time. But it gives you an idea of the things that need to be dealt with, if you want repeated reading to occur automatically.
Of course, once you have an 自動車-read in place, what should happen in the 覚え書き becomes an 問題/発行する. Should new lines just be 追加するd, 追加するd, 追加するd? Once there are, say, 50 lines of data, should the oldest be 除去するd when a new one is 追加するd? Newest at 最高の,を越す? At 底(に届く)? 自動車 scroll the 覚え書き, in the 事例/患者 of the latter? And so on.
A way for the 使用者 to change the frequency of 自動車-read should be 供給するd. That setting should be 記録,記録的な/記録するd and 回復するd 経由で the ini とじ込み/提出する.
So many bells and whistles! So little time!
What was the point of all that? The 使用/適用 we created? I don't think so! Except as a starting point for a more polished 使用/適用.
As an 演習 on which you can sharpen your teeth? 絶対. If working through that has 拡大するd your 技術s, then I am delighted.
Proof that the PCSensor TEMPerLAN is a good 装置, which 現実に 作品, but could use better documentation, and some 代案/選択肢 ソフトウェア? That too!
As explained above, 許す me if I re-cap...
A long way 支援する, I elected to read the data coming from the TEMPerLAN after it is sent a $BB $82 using the "line at a time" method.
This was a Bad Idea, for a (弁護士の)依頼人 使用/適用 for the TEMPerLAN, which いつかs sends $FF as part of the line. A different approach should have been taken, for the TEMPerLAN (弁護士の)依頼人. (LineMode is 罰金 for many needs.)
In the LineMode=誤った 方式, there's a 衝撃を和らげるもの to 持つ/拘留する things arriving 経由で the TCP/IP 関係... the problem is that while the whole line from the TEMPerLAN often arrives in one "chunk", there's no 保証(人).
概して speaking, what we need to do is...
In practice, in TCP002, I 始める,決める up a "衝撃を和らげるもの for the 衝撃を和らげるもの". Whenever something (機の)カム in, I appended it to the contents of a 全世界の string-type variable. As that grew, I watched it, and then dealt with the contents when the whole 返答 to the $BB $82 命令(する) had arrived.
The place to go to learn more is the ICS Wiki. To do things by the "other" method, the one that happens when the socket's LineMode 所有物/資産/財産 is 始める,決める to 誤った, you still use the OnDataAvailable event to know that data has arrived, but that event will be 誘発する/引き起こすd as soon as some data is 利用できる, it won't always wait for the 伝達/伝染 of the whole line. You still use the 構成要素's Receive, or ReceiveStr method within your OnDataAvailable handler.
It isn't terribly difficult to make what you've created "明白な" to anyone on the internet. You will need either a static IP 演説(する)/住所 (which, if you had one, you would know you have), or a dyndns service. I've done a separate guide to why you need, how to 始める,決める up dyndns service.
|
|
If you visit 1&1's 場所/位置 from here, it helps me. They host my website, and I wouldn't put this link up for them if I wasn't happy with their service. They 申し込む/申し出 things for the beginner and the 会社/団体.![]()
Page 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org
....... P a g e . . . E n d s .....