|
|
|
|
What really happens when you fax (1 of many)Class 1(a quick editorial comment. Duncan wrote this, primarily to get familiar with what happens during faxing so he could answer questions in the newsgroup. Oddly enough, this venture made him decide to stay away from faxing, and we haven't seen him in the fax newsgroup since.) The CCITT TR29.2 committee accepted the Class 1 standard for faxing in 1988. At the same time the Class 2 standard was voted on, but not accepted. Some software and hardware manufacturers then unofficially adopted the Class 2 standard. Since the unofficial Class 2 standard was so widely used, the CCITT TR29.2 committee declared the official Class 2 standard would be designated as Class 2.0. In the Class 1 standard, most of the work of sending the fax is done by the application. In class 2 and 2.0, the modems handle a large part of the negotiation. In this tech tip, I will focus on the Class 1 standard (Class 2 and Class 2.0 will be visited in later documents). Before getting into the details of a Class 1 fax transmission, here are a few quirks about faxing to keep in mind.
These quirks in the faxing protocol can lead to some rather interesting behavior. Since carrier is dropped and raised many times during a fax session and is not actually required during the page send, you can end up with a situation in which the connection has dropped and the sender keeps on sending the fax with no way of realizing what happened. Sending a faxThe process of sending a fax using the Class 1 standard can be broken into six steps: configuring your modem for faxing, dialing, negotiation, sending a page, ending the page, and hanging up. Configuring your modem for faxingTo set up your fax to send or receive according to the class 1 standard, you need to send the command: AT+FCLASS=1 DialingAfter setting the fax class, the dialing is accomplished by sending the ATDTxxxxx command. When you dial with the intention of faxing, it will automatically assume a baud rate of 300 baud. This is the rate that is used for negotiating the fax. NegotiationIn the negotiation stage, things are starting to get a little tricky. Once the connection is made, the remote fax will send the NSF frame. The NSF frame contains user requirements that are not part of the fax class 1 standard. After receiving the NSF frame, the sender will send the AT+FRH=3 command. The +FRH and +FTH (receive and transmit HDLC) commands are used for negotiating the fax session. The parameter specified on the command determines the baud rate that will be used as well as the training time required and some assumptions about the hardware involved.
Not all fax machines are required to support all the baud rates. Only the lower ones are required. The normal baud rate for the negotiations is 300 baud, so you will see +FRH=3 and +FTH=3 more any of the other values. When the +FRH command is sent, the carrier is dropped (you may receive a NO CARRIER from the modem at this point) and is raised again at the new baud rate (You should receive a CONNECT from the modem at this point). In addition, the +FRH command tells the other end that it should send some information. There is now parameter to +FRH that indicates what information should be sent. What you get depends on where you are in the faxing process. After the AT+FRH=3 command is sent in response to receiving the NSF frame, the remote fax will then send the CSI (Call Station ID) frame. This frame is transmitted backwards. The local fax will send AT+FRH=3 again causing the remote fax to send the DIS (Digital Identification Signal) frame. The DIS frame contains a bitmask that describes the capabilities of fax sender and receiver. The contents of the DIS frame are:
At this point, we will transmit the AT+FTH=3 which will cause the remote fax to drop the carrier twice. The modem will reply with CONNECT when it is time for us to send the information. The first time we will send the TSI frame. The second time we will send the DCS frame. After the last frame has been sent, we will send the AT+FTS=8 (fax transmit silence – it will transmit 80ms of silence) command. This command will drop the carrier and wait 80ms. After waiting 80ms, we can send the training data. This is just a series of NULLS lasting for 1.5 seconds plus or minus 10%. The AT+FTM=xx command is sent to drop the carrier and negotiate a new baud rate (this takes the same parameter for the baud rate as the +FRH command) and after the modem returns “CONNECT”, the training data is sent. The baud rate used here is the same baud rate that will be used to send the data. After the training data has been sent, the AT+FRH=3 command is sent again and then we get the CFR frame. Sending a pageFinally, after all the negotiations, we can send a page of the fax. Compared to the fax negotiation, this is easy. First we will send the AT+FTM=xx command to drop the carrier and negotiate the baud rate. After the modem replies with CONNECT, and we can transmit the page. Ending the pageAfter the page has been sent, send the AT+FTS=8 command to wait 80ms and then the AT+FTH=3 command to drop the drop the speed to 300 baud. When we get the “CONNECT” response from the modem, we can send the end of page frame. After sending the last line of a page frame, we send the AT+FRH=3 command so that we can receive the MCF frame. The MCF frame is the receiver telling the sender whether it received the page successfully or not. Once we have received that frame, we send the AT+FTH=3 command, when the modem responds with “CONNECT”, we can send the DCN frame. The “Sending a page” and “Ending a page” steps will be performed for each page of the fax. Hanging upThis is probably the easiest step of the entire process. Just send the ATH0 command to the modem to hang it up. Receiving a faxReceiving a fax is very similar to the sending process. Again, it can be broken into six steps: configuring your modem for faxing, answering, negotiation, receiving a page, ending the page, and hanging up. Configuring your modem for faxingThis step is the same as it is for sending a fax, send the AT+FCLASS=1 command to your modem. AnsweringAfter configuring your modem for Class 1 faxing, answering the call is just like answering a data call. APRO will wait for a “RING” response from the modem indicating an incoming call. It will then send the ATA command to tell the modem to answer the call. NegotiationAs with sending, when the connection is made, we will assume it was made at 300 baud. We will send the NSF frame and drop and the modem to connect twice. The first reconnect, we will send the CSI frame, the second we will send the DSI frame. After sending the required frames, send the AT+FRH=3 and receive the TSI frame. Send the AT+FRH=3 command again, and send the DCS frame. Now, we can send the AT+FRM=xx command to set the baud rate for receiving the training data. Wait for the CONNECT; when we get it, it will be followed by the training data, then the carrier will drop. Once that happens, Send the AT+FTH=3 command, and send the CFR frame. Receiving a pageReceiving a page is fairly simple. Send the AT+FRM=xx command to receive data. The data will follow once the modems reconnect. After the page is sent, the carrier will drop. Ending the pageOnce the carrier drops after receiving a page, send the AT+FRH=3 command and wait for the EOP frame. Once the EOP frame has been received, send the AT+FTH=3 command and send the MCF frame. After that, send the AT+FRH=3 command and wait for the DCN frame. Hanging upThis is probably the easiest step of the entire process. We send the ATH0 command to the modem to hang it up. Summary of Class 1 fax commandsHere is a summary of all the commands used by the Class 1 faxing standard. +FCLASSThe +FCLASS command is used for inquiring and setting the fax class. If you call it with an AT+FCLASS?, the modem will return the current state of the modem. For example, a return value of 1 indicates the modem is ready for Class 1 faxing.
If you call it with an AT+FCLASS=?, the modem will return a comma separated list of supported fax classes. For example, a modem might return “0,1” to indicate data and class 1 faxing. The AT+FCLASS=x value will set the modem to use the specified fax class. +FTS and +FRSThe +FTS and +FRS commands will transmit and receive silence respectively. They take a single parameter that specifies the tens of milliseconds of silence that is expected. For example, AT+FTS=8 will transmit 80ms of silence. After transmitting silence, an OK is returned from the modem. When receiving silence, an OK will be returned only if the expected amount of silence is heard on the line. +FTH and +FRHThese commands are used at 300 baud to handle all the negotiation between the two faxes. The +FTH command will cause data framed in the HDLC protocol to be transmitted at the baud rate specified. The end of the data transmitted is indicated by the <DLE><ETX> characters.
The +FRH command will receive data framed in the HDLC protocol at the specified baud rate. +FTM and +FRMThe +FTM and +FRM commands transmit and receive the fax respectively. They will set the baud rate to the parameter specified (AT+FRM=96 to receive a fax at 9600 baud). The <DLE> <ETX> characters will indicate the end of the data. After the fax as has finished, the carrier will be dropped. There is really no error checking at all while the page is sending or being received. +FCERROR and +F4The +FCERROR is used to indicate when a carrier other than what is expected on a +FTM, +FRM, +FTH or +FRH command is found. +FMI, +FMM and +FMRThe +FMI, +FMM and +FMR commands are used to request information about the modem. AT+FMI? will request the manufacturer, AT+FMM? will request the model, and AT+FMR? will request the revision number. The commands are optional and are not supported on all modems. +FLOThe +FLO is an optional command used to set the flow control. It takes a single parameter that indicates the flow control:
For example, AT+FLO=0 would turn XON/XOFF off. +FLO is not supported on all modems and +FLO=2 is very optional. +FPRThe +FPR command allows the baud rate to be fixed at a specific rate. This command can be given at the same time as the +FCLASS=1 command. The command may not be supported on all modems.
Example: +FPR=0 to set the baud rates to be automatically determined. How does this show up in the dispatch log?Now that we have covered the theory, let’s see how the faxing process works from the point of the dispatch log. You can generate a dispatch log by setting the Logging property of your port to tlOn and then specifying an explicit path and file name for you LogName property. For faxing, the default log size is too small; you will need to adjust it up (add a couple of zeros to the end of the log size – that should suffice). In the dispatch logs, the various states of the faxing process are shown on the dispatch log lines with a type field of “Fax”. Fax class 1 receiving states start with “rf1” and fax class 1 transmitting states start with “tf1”. The full list of the fax subtypes is in the AwFax.pas unit. Receiving a faxAPRO v3.03Compiler : Delphi 5Operating System : Windows NT 5.0 Time Type SubType Data OtherData-------- -------- ------------ -------- ---------0000.012 TrDatChg Avail 00000001 0000.013 TrgHdAlc Window 003A0326 0001.032 User 00000000 Receive_one_page,_Class10001.032 TrDatChg Avail 00000001 0001.032 TrigAllc Timer 00000008 0001.032 TrigAllc Timer 00000010 0001.032 TrigAllc Status 0000001B (Output buffer free)0001.032 TrigAllc Status 00000024 (Output buffer used)0001.032 TrigAllc Status 00000029 (Modem status)The default INIT string sent before all faxes. If you have a custom modem init, it would show up before this one. 0001.132 Dispatch WriteCom 00000001 A0001.132 Dispatch WriteCom 00000001 T0001.132 Dispatch WriteCom 00000001 E0001.132 Dispatch WriteCom 00000001 00001.132 Dispatch WriteCom 00000001 Q0001.132 Dispatch WriteCom 00000001 00001.132 Dispatch WriteCom 00000001 V0001.132 Dispatch WriteCom 00000001 10001.132 Dispatch WriteCom 00000001 X0001.132 Dispatch WriteCom 00000001 40001.132 Dispatch WriteCom 00000001 S0001.133 Dispatch WriteCom 00000001 00001.133 Dispatch WriteCom 00000001 =0001.133 Dispatch WriteCom 00000001 00001.133 Dispatch WriteCom 00000001 S0001.133 Dispatch WriteCom 00000001 20001.133 Dispatch WriteCom 00000001 =0001.133 Dispatch WriteCom 00000001 40001.133 Dispatch WriteCom 00000001 30001.133 Dispatch WriteCom 00000001 [0D]0001.133 TrDatChg Timer 00000008 [B6][00][00][00]0001.133 TrDatChg Timer 00000008 [B6][00][00][00]0001.149 Dispatch ReadCom 00000006 [0D][0A]OK[0D][0A] Set fax class 1 0001.251 Dispatch WriteCom 00000001 A0001.251 Dispatch WriteCom 00000001 T0001.251 Dispatch WriteCom 00000001 +0001.251 Dispatch WriteCom 00000001 F0001.251 Dispatch WriteCom 00000001 C0001.251 Dispatch WriteCom 00000001 L0001.251 Dispatch WriteCom 00000001 A0001.251 Dispatch WriteCom 00000001 S0001.251 Dispatch WriteCom 00000001 S0001.251 Dispatch WriteCom 00000001 =0001.251 Dispatch WriteCom 00000001 10001.252 Dispatch WriteCom 00000001 [0D]0001.252 TrDatChg Timer 00000008 [B6][00][00][00]0001.252 TrDatChg Timer 00000008 [B6][00][00][00]0001.262 Dispatch ReadCom 00000006 [0D][0A]OK[0D][0A] Find out what receive modes the modem supports? 0001.475 Dispatch WriteCom 00000001 A0001.475 Dispatch WriteCom 00000001 T0001.475 Dispatch WriteCom 00000001 +0001.475 Dispatch WriteCom 00000001 F0001.475 Dispatch WriteCom 00000001 R0001.475 Dispatch WriteCom 00000001 M0001.475 Dispatch WriteCom 00000001 =0001.475 Dispatch WriteCom 00000001 ?0001.475 Dispatch WriteCom 00000001 [0D] In this case we support 300 baud, 2400 up to 14400. 0001.475 TrDatChg Timer 00000008 [B6][00][00][00]0001.487 Dispatch ReadCom 0000000E [0D][0A]3,24,48,72,70001.494 Dispatch ReadCom 0000000E 3,74,96,97,98,0001.503 Dispatch ReadCom 0000000E 121,122,145,140001.509 Dispatch ReadCom 00000009 6[0D][0A][0D][0A]OK[0D][0A]0001.509 TrgHdAlc Procedure 00000000 0001.509 Fax rfInit 00000000 We reset the fax class as a safeguard 0001.612 Dispatch WriteCom 00000001 A0001.612 Dispatch WriteCom 00000001 T0001.612 Dispatch WriteCom 00000001 +0001.612 Dispatch WriteCom 00000001 F0001.612 Dispatch WriteCom 00000001 C0001.612 Dispatch WriteCom 00000001 L0001.612 Dispatch WriteCom 00000001 A0001.612 Dispatch WriteCom 00000001 S0001.613 Dispatch WriteCom 00000001 S0001.613 Dispatch WriteCom 00000001 =0001.613 Dispatch WriteCom 00000001 10001.613 Dispatch WriteCom 00000001 [0D]0001.613 TrDatChg Timer 00000008 [B6][00][00][00]0001.613 TrDatChg Timer 00000008 [B6][00][00][00]0001.613 TrDatChg Timer 00000010 [12][00][00][00]0001.624 Dispatch ReadCom 00000006 [0D][0A]OK[0D][0A]0001.624 Trigger Avail 00000006 0001.624 Fax rf1Init1 00000000 0001.624 Fax rf1Init1 00000000 Wait for the phone to ring 0001.624 TrDatChg Timer 00000008 Deactivated0002.627 Trigger Timer 000000100002.627 Fax rfWaiting 000000000002.627 TrDatChg Timer 00000010 [12][00][00][00]0003.680 Trigger Timer 00000010...0071.644 TrDatChg Timer 00000010 [12][00][00][00]0072.647 Trigger Timer 000000100072.647 Fax rfWaiting 000000000072.647 TrDatChg Timer 00000010 [12][00][00][00]0073.700 Trigger Timer 000000100073.700 Fax rfWaiting 00000000 0073.700 TrDatChg Timer 00000010 [12][00][00][00]0074.590 Dispatch ReadCom 00000008 [0D][0A]RING[0D][0A]0074.590 Trigger Avail 000000080074.590 Fax rfWaiting 000000000074.590 Fax rfWaiting 000000000074.590 TrDatChg Timer 00000008 [B6][00][00][00]0074.590 Fax rfWaiting 000000000074.590 Fax rfWaiting 000000000074.590 TrDatChg Timer 00000008 [B6][00][00][00] We got a ring, tell the modem to answer the call. 0074.590 Fax rfAnswer 000000000074.690 Dispatch WriteCom 00000001 A0074.690 Dispatch WriteCom 00000001 T0074.690 Dispatch WriteCom 00000001 A0074.690 Dispatch WriteCom 00000001 [0D]0074.690 TrDatChg Timer 00000008 [B6][00][00][00]0074.690 TrDatChg Timer 00000008 D[04][00][00]0074.740 Trigger Timer 00000010 Every second, we have a status timer that fires. You can seehere that it’s taken 5 seconds to see that there is a fax on the other end. 0074.740 Fax rf1SendCSI 000000000074.740 TrDatChg Timer 00000010 [12][00][00][00]0075.793 Trigger Timer 000000100075.793 Fax rf1SendCSI 00000000 0075.794 TrDatChg Timer 00000010 [12][00][00][00]0076.847 Trigger Timer 000000100076.847 Fax rf1SendCSI 00000000 0076.848 TrDatChg Timer 00000010 [12][00][00][00]0077.902 Trigger Timer 000000100077.902 Fax rf1SendCSI 00000000 0077.902 TrDatChg Timer 00000010 [12][00][00][00]0078.956 Trigger Timer 000000100078.956 Fax rf1SendCSI 000000000078.956 TrDatChg Timer 00000010 [12][00][00][00]0079.959 Trigger Timer 000000100079.959 Fax rf1SendCSI 000000000079.959 TrDatChg Timer 00000010 [12][00][00][00] The local fax acknowledges that the remote is a fax and generates a “CONNECT”. 0080.163 Dispatch ReadCom 0000000B [0D][0A]CONNECT[0D][0A]0080.163 Trigger Avail 0000000B We send the CSI frame (Call Station ID) property. It is sent backwards. In this case we sent “MY STATION ID”. It is padded to 20 characters and ends with an “C” followed by an ETX (0x03) and an 0xFF. 0080.163 Fax rf1SendCSI 00000000 0080.163 Fax rf1SendCSI 00000000 0080.183 Dispatch WriteCom 00000001 [FF]0080.183 Dispatch WriteCom 00000001 [03]0080.183 Dispatch WriteCom 00000001 C0080.183 Dispatch WriteCom 00000001 [20]0080.183 Dispatch WriteCom 00000001 [20]0080.183 Dispatch WriteCom 00000001 [20]0080.183 Dispatch WriteCom 00000001 [20]0080.183 Dispatch WriteCom 00000001 [20]0080.183 Dispatch WriteCom 00000001 [20]0080.183 Dispatch WriteCom 00000001 [20]0080.183 Dispatch WriteCom 00000001 D0080.184 Dispatch WriteCom 00000001 I0080.184 Dispatch WriteCom 00000001 [20]0080.184 Dispatch WriteCom 00000001 N0080.184 Dispatch WriteCom 00000001 O0080.184 Dispatch WriteCom 00000001 I0080.184 Dispatch WriteCom 00000001 T0080.184 Dispatch WriteCom 00000001 A0080.184 Dispatch WriteCom 00000001 T0080.184 Dispatch WriteCom 00000001 S0080.184 Dispatch WriteCom 00000001 [20]0080.184 Dispatch WriteCom 00000001 Y0080.184 Dispatch WriteCom 00000001 M0080.184 Dispatch WriteCom 00000001 [10]0080.184 Dispatch WriteCom 00000001 [03]0080.184 TrDatChg Timer 00000008 [B6][00][00][00] The modems will reconnect after the CSI frame was sent. 0081.037 Trigger Timer 00000010 0081.037 Fax rf1SendDIS 00000000 0081.037 TrDatChg Timer 00000010 [12][00][00][00]0082.045 Dispatch ReadCom 0000000B [0D][0A]CONNECT[0D][0A]0082.045 Trigger Avail 0000000B Now we send the DIS (Digital Identification Signal) frame. The DIS is a bitmask that describes what our capabilities are. This is not reversed. 0082.045 Fax rf1SendDIS 00000000 0082.045 Fax rf1SendDIS 00000000 0082.066 Dispatch WriteCom 00000001 [FF]0082.066 Dispatch WriteCom 00000001 [13]0082.066 Dispatch WriteCom 00000001 [80]0082.066 Dispatch WriteCom 00000001 [00]0082.066 Dispatch WriteCom 00000001 N0082.066 Dispatch WriteCom 00000001 [F9]0082.066 Dispatch WriteCom 00000001 [00]0082.066 Dispatch WriteCom 00000001 [10]0082.066 Dispatch WriteCom 00000001 [03]0082.066 TrDatChg Timer 00000008 [B6][00][00][00]0082.066 Trigger Timer 00000010 0082.066 Fax rf1SendDIS 00000000 0082.066 TrDatChg Timer 00000010 [12][00][00][00] We get an OK after sending the DIS frame 0082.463 Dispatch ReadCom 00000006 [0D][0A]OK[0D][0A]0082.463 Trigger Avail 00000006 0082.463 Fax rf1SendDIS 00000000 0082.463 Fax rf1SendDIS 00000000 We send an AT+FRH=3 to set the baud rate to 300 and receive HDLC data. 0082.906 Dispatch WriteCom 00000001 A0082.906 Dispatch WriteCom 00000001 T0082.908 Dispatch WriteCom 00000001 +0082.908 Dispatch WriteCom 00000001 F0082.908 Dispatch WriteCom 00000001 R0082.908 Dispatch WriteCom 00000001 H0082.908 Dispatch WriteCom 00000001 =0082.908 Dispatch WriteCom 00000001 30082.908 Dispatch WriteCom 00000001 [0D]0082.908 TrDatChg Timer 00000008 [B6][00][00][00]0082.908 TrDatChg Timer 00000008 6[00][00][00]0083.109 Trigger Timer 00000010 0083.109 Fax rf1CollFrms 00000000 0083.109 TrDatChg Timer 00000010 [12][00][00][00] We have connected at 300 baud, so the modem sends a “CONNECT”. 0083.285 Dispatch ReadCom 0000000B [0D][0A]CONNECT[0D][0A]0083.285 Trigger Avail 0000000B 0083.285 Fax rf1CollFrms 00000000 0083.285 Fax rf1CollFrms 00000000 0083.286 TrDatChg Timer 00000008 [B6][00][00][00] We start getting HDLC data. In this case we get the remotes station ID: “Kl 719 260 7151“. Again this is backwards and ends with the “C” ETX 0xff. 0083.662 Dispatch ReadCom 00000001 [FF]0083.662 Trigger Avail 00000001 0083.662 Fax rf1CollFrms 00000000 0083.662 Fax rf1CollFrms 00000000 0083.689 Dispatch ReadCom 00000001 [03]0083.689 Trigger Avail 00000001 0083.689 Fax rf1CollFrms 00000000 0083.689 Fax rf1CollFrms 00000000 0083.716 Dispatch ReadCom 00000001 C0083.716 Trigger Avail 00000001 0083.716 Fax rf1CollFrms 00000000 0083.716 Fax rf1CollFrms 00000000 0083.742 Dispatch ReadCom 00000001 10083.742 Trigger Avail 00000001 0083.742 Fax rf1CollFrms 00000000 0083.742 Fax rf1CollFrms 00000000 0083.769 Dispatch ReadCom 00000001 50083.769 Trigger Avail 00000001 0083.769 Fax rf1CollFrms 00000000 0083.769 Fax rf1CollFrms 00000000 0083.796 Dispatch ReadCom 00000001 10083.796 Trigger Avail 00000001 0083.796 Fax rf1CollFrms 00000000 0083.796 Fax rf1CollFrms 00000000 0083.822 Dispatch ReadCom 00000001 70083.822 Trigger Avail 00000001 0083.822 Fax rf1CollFrms 00000000 0083.822 Fax rf1CollFrms 00000000 0083.849 Dispatch ReadCom 00000001 [20]0083.849 Trigger Avail 00000001 0083.849 Fax rf1CollFrms 00000000 0083.849 Fax rf1CollFrms 00000000 0083.876 Dispatch ReadCom 00000001 00083.876 Trigger Avail 00000001 0083.876 Fax rf1CollFrms 00000000 0083.876 Fax rf1CollFrms 00000000 0083.902 Dispatch ReadCom 00000001 60083.902 Trigger Avail 00000001 0083.902 Fax rf1CollFrms 00000000 0083.902 Fax rf1CollFrms 00000000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||