public void Post([FromBody] Book book)
        {
            //var booklist = new List<Book>();
            string[] lines = new string[] { book.VALUE };

            if (!SerialConnection.portStatus)
            {
                SerialConnection.PortOpen(book.COM_SET, book.Author);
            }

            if (SerialConnection.portStatus == false)
            {
                var resp = new HttpResponseMessage(HttpStatusCode.Forbidden)
                {
                    Content      = new StringContent(string.Format("{0}", SerialConnection._PortMessage)),
                    ReasonPhrase = SerialConnection._PortMessage
                };

                throw new HttpResponseException(resp);
            }
            else
            {
                var resp = new HttpResponseMessage(HttpStatusCode.Created)
                {
                    Content      = new StringContent(string.Format("{0}", SerialConnection._PortMessage)),
                    ReasonPhrase = SerialConnection._PortMessage
                };

                throw new HttpResponseException(resp);
            }
        }
        //DELETE api/book/1
        public void Delete(int Id)
        {
            SerialConnection.closePort();
            var resp = new HttpResponseMessage(HttpStatusCode.OK);

            throw new HttpResponseException(resp);
        }
        //GET api/book/1
        //public Book Get(int Id)
        public Book Get(string Id)
        {
            string nama;

            ourbooks = InitBooks();
            nama     = "";

            if (SerialConnection.portStatus)
            {
                SerialConnection.write(Id);
            }
            //SerialConnection.write(Id);
            //SerialConnection.write("help");
            var result = (from b in ourbooks
                          //where b.Id == Id
                          where b.Id == 1
                          select b).FirstOrDefault();


            if (result == null)
            {
                var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent(string.Format("No book with ID = {0}", Id)),
                    ReasonPhrase = "Book ID Not Found"
                };
                throw new HttpResponseException(resp);
            }

            if (Id.Equals("2"))
            {//Jika Sucromat yang ngirim
                SerialConnection._Value = "";
            }

            return(result);
        }
 public void Stop()
 {
     SerialConnection.closePort();
 }