Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Electrawn

Archived
  • Posts

    1
  • Joined

  • Last visited

Profile Information

  • Real Name
    Jason Potkanski

Electrawn's Achievements

  1. Some time in the next few days I'm going to look at getting a thermal printer working. From the FEDEX API Manual: Received from FedEx: 0,"121"33,"AA"1136,"XY"30,"XY AYZA"29,"470001338040"526,"0201"1402,"2.0"1419,"25.22"1416,"24.25"1417,".97"1090,"USD"1 089,"01552"1092,"5"65,"40048946120000014700013380402018"194,"THU"195,"EWR"409,"01JUN00" 431,"N"188,? <Label Binary Data Stored Here> ?99,"" NOTE: Field 188 will contain the label data. In the next section we cover how to use this data buffer to print the FedEx shipping label. When a Ship a Package transaction is performed, the data necessary for producing a shipping label (and possibly a COD return label) is returned in one or more fields. The kind of label data returned depends on the printer type and format specified in your Ship request. Using buffer data to print PNG or Thermal labels The rule for encoding the PNG or thermal image in the returned label buffer was designed to eliminate certain illegal characters (byte values) by replacing them with an escape sequence. Those values that are not allowed include: NULL (0x00 hex) Double Quote (0x22 hex) The percent character ?%? (0x25 hex) is used as the escape character, and therefore it must be replaced where it occurs naturally. Whenever a disallowed character or the escape character '%' is encountered, it is replaced by the escape character ?%? (0x25 hex) followed by two characters comprising the hexadecimal numeral representing the value of the character. For example, the NULL character (0x00 hex) is replaced by three characters: '%' (0x25) '0' (0x30) '0' (0x30) The percent character 0x25 is replaced by three characters: '%' (0x25) '2? (0x32) '5' (0x35) The algorithm for decoding the PNG image in the returned label buffer is as follows. Read bytes from the label field one at a time. When a byte read is not equal to the ?%? character (0x25 hex), pass it through unchanged. When a byte is read that is equal to the ?%? character (0x25 hex), read an additional two bytes, which will each take a value from ?0? (0x30 hex) through ?9? (0x39 hex) or ?A? (0x41 hex) through ?F? (0x46 hex). These two bytes are interpreted as a character representation of a two-digit hexadecimal numeral ranging from 0x00 through 0xFF. The single byte having the integral value represented by that numeral is appended to your output. For example, when the 3-byte string '%22' is encountered, ? ? ? (0x22) - the double quote character - is passed out. When the 3 bytes '%00' are read, the null character is written. In essence, the developer will need to take the data received from FedEx and store it in a buffer that has sufficient memory to hold the entire data stream. Once the data has been stored, the program might use a function similar to the one described below in order to parse the data in the buffer and extract only the PNG image data. From that point, the developers program must be able to call a print function to send the image to the laser printer. The following sample ?C? function illustrates how this is accomplished. int create_fedex_ship_label(char *receive_buffer) { FILE *fedex_label; int c; int data_decoded = 0; int temp_label_counter; int label_data_found = 0; int result = 1; int load_label_data = 0; char data; char temp_label_buffer[20]; char label_file_name[20]= {?FedEx Label.png?}; char data_field_buffer[6]= {?188,?}; if((fedex_label = fopen(label_file_name, "wb")) == NULL) { return(1); } c = 0; while(data_decoded != 1) { data = receive_buffer[c]; if(data == '1') { temp_label_buffer[temp_label_counter] = data; temp_label_counter++; c++; data = receive_buffer[c]; if((data == '8') && (temp_label_buffer[0] == '1')) { temp_label_buffer[temp_label_counter] = data; temp_label_counter++; c++; data = receive_buffer[c]; } else { temp_label_counter = 0; } if((data == '8') && (temp_label_buffer[1] == '8')) { temp_label_buffer[temp_label_counter] = data; temp_label_counter++; c++; data = receive_buffer[c]; } else { temp_label_counter = 0; } if((data == ',') && (temp_label_buffer[2] == '8')) { temp_label_buffer[temp_label_counter] = data; temp_label_counter++; c++; temp_label_buffer[temp_label_counter] = 0x00; label_data_found = 1; } else { temp_label_counter = 0; } } else c++; if(label_data_found) { result = strcmp(temp_label_buffer, data_field_buffer); if(result == 0) load_label_data = 1; data = receive_buffer[c]; } if(load_label_data) { data = '0'; c++; while(data != 0x22) { data = receive_buffer[c]; c++; if(data != '%') fprintf(fedex_label, "%c", data); if(data == '%') { for(e=0; e<2; e++) { data = receive_buffer[c]; c++; if(((data >= 0x30) && (data <= 0x39)) || ((data >= 0x41) && (data <= 0x46))) { if(e == 1) { d = data; d = d & 0x0f; if((data >= 0x41) && (data <= 0x46)) d += 9; store = store | d; } else { d = data; d = d & 0x0f; if((data >= 0x41) && (data <= 0x46)) d += 9; store = d << 4; } } } fprintf(fedex_label, "%c", store); } } data_decoded = 1; } } fclose(fedex_label); return(0); English? The data return needs to be sanitized for % and Null. I don't have a thermal printer handy but I'll try and convert this C code to PHP. -Jason Potkanski Electrawn GameVerse
×
×
  • Create New...